trinitrotoluen Posted January 20, 2009 Share Posted January 20, 2009 (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 January 20, 2009 by trinitrotoluen Link to comment Share on other sites More sharing options...
azure Posted January 20, 2009 Share Posted January 20, 2009 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 Link to comment Share on other sites More sharing options...
trinitrotoluen Posted January 20, 2009 Author Share Posted January 20, 2009 $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 Link to comment Share on other sites More sharing options...
azure Posted January 20, 2009 Share Posted January 20, 2009 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 Link to comment Share on other sites More sharing options...
Paulie Posted January 20, 2009 Share Posted January 20, 2009 (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]) EndIfUntested. Edited January 20, 2009 by Paulie Link to comment Share on other sites More sharing options...
Robjong Posted January 20, 2009 Share Posted January 20, 2009 @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]) Link to comment Share on other sites More sharing options...
TerarinK Posted January 20, 2009 Share Posted January 20, 2009 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 Link to comment Share on other sites More sharing options...
trinitrotoluen Posted January 20, 2009 Author Share Posted January 20, 2009 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 ! Link to comment Share on other sites More sharing options...
TerarinK Posted January 20, 2009 Share Posted January 20, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now