nend Posted May 21, 2023 Share Posted May 21, 2023 (edited) I need your Regex skils. I need a number out of this, if the number is above the 1 then it works, but if it is below the 1 examle 0.96 it shows 96. How can I fix this? #include <StringConstants.au3> Local $teststring1 = "(000.96*A)"; has to be 0.96 Local $teststring2 = "(001.96*A)"; has to be 1.96 Local $array = StringRegExp($teststring1, "\(0*\.*(.*)\*", $STR_REGEXPARRAYGLOBALMATCH, 1) ConsoleWrite($array[0] & @CRLF) Edited May 21, 2023 by nend Link to comment Share on other sites More sharing options...
Developers Jos Posted May 21, 2023 Developers Share Posted May 21, 2023 Something like this: "\(0*(\d*\.?\d+)\*"" SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
nend Posted May 21, 2023 Author Share Posted May 21, 2023 Allmost, this will output .96 but I need 0.96, do you know a sollution for this? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 21, 2023 Developers Share Posted May 21, 2023 (edited) Is there always a decimal point in the value? In that case "\(0*(\d+\.\d+)\*" Edited May 21, 2023 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
nend Posted May 21, 2023 Author Share Posted May 21, 2023 (edited) No not always, this is also a example (005*A). So if there is a decimal point and there is a other number before the decimal point then zero then capture and else strip al leading zero's (000.96*A) = 0.96 (001.96*A) = 1.96 (005*A) = 5 The amount of leading zero's can be different. Edited May 21, 2023 by nend Link to comment Share on other sites More sharing options...
Solution TheXman Posted May 21, 2023 Solution Share Posted May 21, 2023 (edited) Why not use the Number() function for such a simple transformation? ConsoleWrite(Number("000.96*A") & @CRLF) ConsoleWrite(Number("001.96*A") & @CRLF) ConsoleWrite(Number("005*A") & @CRLF) Outputs: 0.96 1.96 5 Edited May 21, 2023 by TheXman nend 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...
nend Posted May 21, 2023 Author Share Posted May 21, 2023 Hmm, totaly overlooked that. Thanks @TheXman and @Jos for helping TheXman 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted May 21, 2023 Developers Share Posted May 21, 2023 In case you are curious how to do that in regex: This is one should work: #include <StringConstants.au3> test("(000.96*A)") test("(001.96*A)") test("(012.96*A)") test("(005*A)") Func test($input) Local $array = StringRegExp($input, "\(0*((?:\d+\.\d+)?\d+)\*", $STR_REGEXPARRAYGLOBALMATCH, 1) ConsoleWrite($array[0] & @CRLF) EndFunc ;==>test Jos nend 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mikell Posted May 21, 2023 Share Posted May 21, 2023 Simpler : "0*(\d+(\.\d+)?)" nend 1 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