Jump to content

[solved] StringRegExp() problem


Exit
 Share

Recommended Posts

#include <Array.au3>
$sTestString = "23,67no_digits_here ID=1234567890terminator xxxxx"
$sPattern = "((\d|,)*)(?:.*ID=)((\d)*)(?:terminator)"
$aResult = StringRegExp($sTestString, $sPattern, 1)
If @error Then Exit MsgBox(0, "Error", "Variable >$aResult< not an array" & @CRLF & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended)
_ArrayDisplay($aResult)

When running this code, there are 4 lines in the array. I expected 2 lines:

line0=23,67

line1=1234567890

What pattern will produce only 2 lines? :P

Edited by forumer100

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

#include <Array.au3>
$sTestString = "23,67no_digits_here ID=1234567890terminator xxxxx"
$sPattern = "((\d|,)*)(?:.*ID=)((\d)*)(?:terminator)"
$aResult = StringRegExp($sTestString, $sPattern, 1)
If @error Then Exit MsgBox(0, "Error", "Variable >$aResult< not an array" & @CRLF & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended)
_ArrayDisplay($aResult)

When running this code, there are 4 lines in the array. I expected 2 lines:

line0=23,67

line1=1234567890

What pattern will produce only 2 lines? :P

Something like this:

$sPattern = "(\d*,\d*).*?ID=(\d*)"

Link to comment
Share on other sites

Something like this:

$sPattern = "(\d*,\d*).*?ID=(\d*)"

Yes, a step nearer to the goal.

But sometimes, there is no comma in the first number. (only dollars, no cents)

#include <Array.au3>
$sTestString1 = "23,67no_digits_here ID=1234567890terminator xxxxx"
$sTestString2 = "23no_digits_here ID=1234567890terminator xxxxx"
$sPattern = "(\d*,\d*).*?ID=(\d*)" 
$aResult = StringRegExp($sTestString1, $sPattern, 1)
If @error Then Exit MsgBox(0, "Error", "Variable >$aResult< not an array" & @CRLF & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended)
_ArrayDisplay($aResult)
$aResult = StringRegExp($sTestString2, $sPattern, 1)
If @error Then Exit MsgBox(0, "Error", "Variable >$aResult< not an array" & @CRLF & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended)
_ArrayDisplay($aResult)

Edit: Got the answer myself.

$sPattern = "([,0123456789]*).*?ID=(\d*)"

Edited by forumer100

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...