Sign in to follow this  
Followers 0
trinitrotoluen

Help for String Regular Express

9 posts in this topic

#1 ·  Posted (edited)

Hi, I wrote :

$asResult = StringRegExp("Your balance is $6.68.", '((?:[$])[0-9]{1,4}.[0-9]{1,4})', 1)

If @error == 0 Then

MsgBox(0, "SRE Example 6 Result", $asResult[0])

EndIf

I wanna extract only 6.68 not including the $ sign. How can I do ? The code above doesn't work.

Notice : The number of balance changes everytime.

thx !

Edited by trinitrotoluen

Share this post


Link to post
Share on other sites



Hi, I wrote :

I wanna extract only 6.68 not including the $ sign. How can I do ? The code above doesn't work.

Notice : The number of balance changes everytime.

thx !

$asResult = StringRegExp("Your balance is $6.68.", '((?:[$])[0-9]{1,4}.[0-9]{1,4})', 1)
If @error == 0 Then
$asResult[0] = StringReplace($asResult[0],"$","")
MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf

Share this post


Link to post
Share on other sites

$asResult = StringRegExp("Your balance is $6.68.", '((?:[$])[0-9]{1,4}.[0-9]{1,4})', 1)
If @error == 0 Then
$asResult[0] = StringReplace($asResult[0],"$","")
MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf
Thank you for your reply, but I wanna catch the number in one action. Is it possible ? Thank again :)

Share this post


Link to post
Share on other sites

Thank you for your reply, but I wanna catch the number in one action. Is it possible ? Thank again :)

$asResult = StringRegExp("Your balance is $6.68.", '([0-9]{1,4}.[0-9]{1,4})', 1)
If @error == 0 Then
MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I think think you should escape the "." with a "/" character, because otherwise it would catch "$234p000"

$asResult = StringRegExp("Your balance is $6.68.", '(?:/$)(/d{1,4}/./d{1,4})', 1)
If @error == 0 Then
MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf
Untested. Edited by Paulie

Share this post


Link to post
Share on other sites

@paulie its backslash, "\"

$asResult = StringRegExp("Your balance is $6.68.", '\$(\d{1,4}\.\d{1,4})', 3) 
If Not @error Then MsgBox(0, "SRE Example 6 Result", $asResult[0])

Share this post


Link to post
Share on other sites

Perhaps you should use a open amount. Because right now your forgetting what about numbers over (4) and also what if the number has got a "," in it?

$asResult = StringRegExp($sValue, "(?:\$)([0-9,]*\.\d{0,2})", 3)
If Not @error Then MsgBox(0, "SRE Example 6 Result", $asResult[0])

Here is a listing, I even corrected the amount so $1.25 will work as well as $10,435.541 as it will recognize the , and well as all the number. However with must debate of this I rounded it the the floor() of the cents so 541 would equal 54 the only problem I would have with this would be 549 becase it to would be floored to 54 cents. So make sure if you want to do that to the full number then correct the "\.\d{0,2}" to "\.\d*" then add a check amount and round it using the rounding functions.

I came across another problem and I don't know if you'll incounter it but it you get no $ you recieve the error that is normally given out. I guess you need to know what it says before you are given a price be using a space didn't work as it would be several space mark so you get several on a array, however you do get them all there though. Just so you do know about this.


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

Perhaps you should use a open amount. Because right now your forgetting what about numbers over (4) and also what if the number has got a "," in it?

$asResult = StringRegExp($sValue, "(?:\$)([0-9,]*\.\d{0,2})", 3)
If Not @error Then MsgBox(0, "SRE Example 6 Result", $asResult[0])

Here is a listing, I even corrected the amount so $1.25 will work as well as $10,435.541 as it will recognize the , and well as all the number. However with must debate of this I rounded it the the floor() of the cents so 541 would equal 54 the only problem I would have with this would be 549 becase it to would be floored to 54 cents. So make sure if you want to do that to the full number then correct the "\.\d{0,2}" to "\.\d*" then add a check amount and round it using the rounding functions.

I came across another problem and I don't know if you'll incounter it but it you get no $ you recieve the error that is normally given out. I guess you need to know what it says before you are given a price be using a space didn't work as it would be several space mark so you get several on a array, however you do get them all there though. Just so you do know about this.

Thank you very much but I don't understand what's difference between flag 1 and flag 3 in StringRegExp func. thx !

Share this post


Link to post
Share on other sites

Flag one and three are for a array to be built, $asResult, so you need to use [] when telling it to do something another topic would be multi-dimensional arrays but not going to talk about those. However flag three declares it to be global so you can use it anywhere in your program flag one you can only use it the immediate area or better yet the local zone

Flag zero is used as a True or False if it has found it it will use True otherwise use False

Flag two and four are pretty much the same except the four is the multi-dimensional array


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

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