knightstalker Posted April 29, 2020 Share Posted April 29, 2020 I am looking for help with a StringRegExpReplace function that only grabs the numbers plus a "." and "%" currently I have "[^0-9.%]" which mostly works, but I and looking to only to match if it is at the end of the string. Example string: "DW-4 2.50%" my expression also leaves the preceding "4" I have tried using $ \b \z and a few others with no success. Any suggestions? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted April 29, 2020 Share Posted April 29, 2020 @knightstalker Could you please post more examples with the expected results? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
faustf Posted April 29, 2020 Share Posted April 29, 2020 i am not specialist for regexp , (you know a maxim ? ...... A programmer has a problem. He decides to solve it using regular expressions. Now he has two problems. ) somthing like this -(.*?)% and when call array add % Link to comment Share on other sites More sharing options...
knightstalker Posted April 29, 2020 Author Share Posted April 29, 2020 additional examples "Ford Prius 1%" "Cotton Candy Non Circus7.5%" "Francos Absolute .5%" results would be 1% 7.5% .5% Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted April 29, 2020 Share Posted April 29, 2020 (edited) @knightstalker Maybe something like this: '([\d.%]+$)' Edited April 29, 2020 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
knightstalker Posted April 29, 2020 Author Share Posted April 29, 2020 10 minutes ago, FrancescoDiMuro said: @knightstalker Maybe something like this: '([\d.%]+$)' Well done! works like a charm. Thanks! Link to comment Share on other sites More sharing options...
mikell Posted April 29, 2020 Share Posted April 29, 2020 (edited) @FrancescoDiMuro Your expression allows 5.% - which is inconsistent Please try this #Include <Array.au3> $s = "Ford Prius 1%" & @crlf & _ "DW-4 6.66% test" & @crlf & _ "DW-4 6.%" & @crlf & _ "DW-4 2.50%" & @crlf & _ "Cotton Candy Non Circus7.5%" & @crlf& _ "Francos Absolute .5%" $res = StringRegExp($s, '(?m)((?:\d*\.?\d+)%)$', 3) _ArrayDisplay($res) Edited April 29, 2020 by mikell Musashi and FrancescoDiMuro 2 Link to comment Share on other sites More sharing options...
Deye Posted April 29, 2020 Share Posted April 29, 2020 $a = StringRegExp($var, '(\d.*)', 3) _ArrayDisplay($a) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted April 30, 2020 Share Posted April 30, 2020 @mikell It was kinda late when I posted that reply, and the OP request was not clear enough since it was like he wanted to get other numbers too. Thanks by the way Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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