Sign in to follow this  
Followers 0
Exit

[solved] StringRegExp() problem

3 posts in this topic

#1 ·  Posted (edited)

#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

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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*)"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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
Sign in to follow this  
Followers 0