BatMan22 Posted April 17, 2018 Share Posted April 17, 2018 Regex101 gives me a different matching then Autoit, and I don't know what I'm doing wrong, guessing regex versions are slightly different.. help? What I am running: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, ".+?(?=\d)", "") ; Delete Everything before numbers What I am expecting is for it to match everything BEFORE 0.0118, which works on regex101 and to delete it.. What I end up with is "3". Link to comment Share on other sites More sharing options...
golfinhu Posted April 17, 2018 Share Posted April 17, 2018 1 hour ago, BatMan22 said: Regex101 gives me a different matching then Autoit, and I don't know what I'm doing wrong, guessing regex versions are slightly different.. help? What I am running: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, ".+?(?=\d)", "") ; Delete Everything before numbers What I am expecting is for it to match everything BEFORE 0.0118, which works on regex101 and to delete it.. What I end up with is "3". $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, "^(.+?\d+\.\d+)", "") ; Delete Everything before numbers MsgBox(0,'',$preedit) try it. Link to comment Share on other sites More sharing options...
BatMan22 Posted April 17, 2018 Author Share Posted April 17, 2018 (edited) @golfinhu, am I missing something? I ran it, and it matched the 0.0118 as well, I want to keep that. I just want to delete everything before the first number, 0.0118, but I need it to be smart because that number could be anything. Edited April 17, 2018 by BatMan22 Link to comment Share on other sites More sharing options...
iamtheky Posted April 17, 2018 Share Posted April 17, 2018 (edited) 1 hour ago, BatMan22 said: Regex101 gives me a different matching then Autoit, and I don't know what I'm doing wrong, guessing regex versions are slightly different.. help? Its fine, you just only want to replace the first match with the blank string $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " msgbox(0, '' , StringRegExpReplace($preedit, ".+?(?=\d)", "" , 1)) You are really matching everything in groups of things up to the next number with that regex, so whether it is the best one for the job is debatable #include<array.au3> $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " _ArrayDisplay(StringRegExp($preedit, ".+?(?=\d)", 3)) Edited April 17, 2018 by iamtheky BatMan22 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
TheXman Posted April 17, 2018 Share Posted April 17, 2018 If you want to delete everything from the beginning of the line until the first number, then this should work also: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, "^[^\d]*", "") ConsoleWrite(StringFormat("$preedit = %s", $preedit) & @CRLF) BatMan22 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
TheXman Posted April 17, 2018 Share Posted April 17, 2018 (edited) 11 hours ago, BatMan22 said: Regex101 gives me a different matching then Autoit, and I don't know what I'm doing wrong, guessing regex versions are slightly different.. help? What I am running: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, ".+?(?=\d)", "") ; Delete Everything before numbers The reason that you didn't get the expected result is because, by default, the StringRegExReplace() does a global replace. If you would have added a "1" for the count parameter, it would have worked as you expected. $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, ".+?(?=\d)", "", 1) ; Delete Everything before numbers ConsoleWrite(StringFormat("$preedit = %s", $preedit) & @CRLF) Or you could have simply asserted that it should only look from the start. Then you wouldn't have needed to add a count parameter. It would have looked like this: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, "^.+?(?=\d)", "") ; Delete Everything before numbers ConsoleWrite(StringFormat("$preedit = %s", $preedit) & @CRLF) Edited April 17, 2018 by TheXman Added an additional way that original code could have been modified to work. BatMan22 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
BatMan22 Posted April 17, 2018 Author Share Posted April 17, 2018 18 hours ago, TheXman said: The reason that you didn't get the expected result is because, by default, the StringRegExReplace() does a global replace. If you would have added a "1" for the count parameter, it would have worked as you expected. $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, ".+?(?=\d)", "", 1) ; Delete Everything before numbers ConsoleWrite(StringFormat("$preedit = %s", $preedit) & @CRLF) Or you could have simply asserted that it should only look from the start. Then you wouldn't have needed to add a count parameter. It would have looked like this: $preedit = "Cl K 0.0118 Wt % 7.91E-4 121.3 290.3 " $preedit = StringRegExpReplace($preedit, "^.+?(?=\d)", "") ; Delete Everything before numbers ConsoleWrite(StringFormat("$preedit = %s", $preedit) & @CRLF) THIS! This is what I was looking for.. Thank you dude. 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