gamepin126 Posted December 21, 2009 Posted December 21, 2009 (edited) The relevant code's quite large, but this is the primary issue I'm having. I'm using RegexBuddy to test my patterns, and it has no issue returning the value I want. Test string : "value 795.45 23.57% 64.28" Pattern : "^value\s{2,}\d+(\.\d+)?" Both without quotes, of course. $input = InputBox("input", "") $pattern = InputBox("pattern", "") $array = StringRegExp($input, $pattern, 1) If @error = 0 Then $nOffset = @extended Else ExitLoop EndIf for $i = 0 to UBound($array) - 1 msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i]) Next Now, that pattern should return "value 795.45" however, it only returns ".45". Is this intended, or an alternate method of getting the string I want? I've had this issue every time I've used optional groups. It's the only thing that gets returned. Edited December 21, 2009 by gamepin126
danielkza Posted December 21, 2009 Posted December 21, 2009 I think you messed up your pattern (posted the wrong one), because a string starting with 'value' will never match '^white'.
gamepin126 Posted December 21, 2009 Author Posted December 21, 2009 (edited) I think you messed up your pattern (posted the wrong one), because a string starting with 'value' will never match '^white'.Ah, I guess I did. But that's not the issue. I'll fix that in the post but those are just test words. Edited December 21, 2009 by gamepin126
danielkza Posted December 21, 2009 Posted December 21, 2009 (edited) Yeah, I figured you would have noticed it. But your problem is very simple to solve: some RegEx software (like, I assume, RegexBuddy) default to returning the whole match in the first element of the returned array. AutoIT doesn't do that: you have to instruct it to do so by using flag 2. "2 - Return array of matches including the full match (Perl / PHP style)." Edited December 21, 2009 by danielkza
gamepin126 Posted December 21, 2009 Author Posted December 21, 2009 Yeah, I figured you would have noticed it. But your problem is very simple to solve: some RegEx software (like, I assume, RegexBuddy) default to returning the whole match in the first element of the returned array.AutoIT doesn't do that: you have to instruct it to do so by using flag 2."2 - Return array of matches including the full match (Perl / PHP style)."That did it, thanks. And thanks for the quick responses. However, it's also returning the correct match, and ".45" in the next element which is a little annoying, but workable.
danielkza Posted December 21, 2009 Posted December 21, 2009 (edited) Just make the last group non-capturing: "^value\s{2,}\d+(?:\.\d+)?" Edited December 21, 2009 by danielkza
gamepin126 Posted December 21, 2009 Author Posted December 21, 2009 Awesome, I'm still new to regex. Thanks again!
GEOSoft Posted December 21, 2009 Posted December 21, 2009 RegExBuddy is not great for use with the PCRE reg ex engine. I've actually stopped using it entirely. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
gamepin126 Posted December 21, 2009 Author Posted December 21, 2009 (edited) RegExBuddy is not great for use with the PCRE reg ex engine. I've actually stopped using it entirely.Hmm, so then are you using Expresso? It's the only other editor I know of. That's also really unfortunate to hear. I use EditPad Pro as my main text editor, it's so handy! Edited December 21, 2009 by gamepin126
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