Mocha Posted April 3, 2018 Share Posted April 3, 2018 (edited) Hi everyone, I am kind of new to Autoit, and right now I am trying to sort out a string and display the way I wanted. I tried to code with the following code, however, the output result does not seem to be the way I want. The output shows 100.11 with a whitespace, but I actually want a result like 100.11 9 Please advise how could I display the way I want by using the regexp, I am kind of stuck now. Thank you so much for helping And here is the code: $strLine = "whatever : whatsoever [100.11 Q9, c, 5]" $sortString = StringRegExpReplace ($strLine, '[[:alpha:]\s\-\[\]]', "") $filterString = StringRegExp ($sortString,'([0-9]]{1,6})', $STR_REGEXPARRAYMATCH,1) MsgBox(0, "", $filterString) Edited April 8, 2018 by Mocha Link to comment Share on other sites More sharing options...
Andreik Posted April 3, 2018 Share Posted April 3, 2018 Your description is vague. Is this all your script has to do? This filter has to be apply to other strings? If yes how in whici way these strings are different? Mocha 1 Link to comment Share on other sites More sharing options...
Malkey Posted April 3, 2018 Share Posted April 3, 2018 This filters "100.11 Q9" to "100.11 9" by removing all ASCII letters. $strLine = "100.11 Q9" $sortString = StringRegExpReplace($strLine, '[[:alpha:]]', "") ; Removes all ASCII letters. MsgBox(0, "", $sortString, 2) Mocha 1 Link to comment Share on other sites More sharing options...
Mocha Posted April 3, 2018 Author Share Posted April 3, 2018 @Andreik Hi...sorry that I didn't make my question clear because I actually just want to sort the string with all numbers without the letter Q, but I just looked into the help file about the tutorial of StringRegExp, and that's how I learnt from that...but I kind of stuck because I am not familiar and comfortable with the Regular Expression yet. @Malkey Thank you for helping me with the code, I didn't even think of I could use in this way...thank you so much... I really want to learn well on RegExp, but I am still struggling on that... Link to comment Share on other sites More sharing options...
abberration Posted April 3, 2018 Share Posted April 3, 2018 (edited) I do not understand your question. Do you have more strings you need to omit letters and then sort them? If so, can you give some examples of other strings? Also, do you want the space in the string? If you do that will affect how your numbers will be sorted. Edited April 3, 2018 by abberration Mocha 1 Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Malkey Posted April 4, 2018 Share Posted April 4, 2018 This also works. $strLine = "100.11 Q9" $sortString = StringRegExpReplace($strLine, '[A-Za-z]', "") ; Removes all ASCII letters. ; or $sortString = StringRegExpReplace($strLine, '(?i)[A-Z]', "") MsgBox(0, "", $sortString, 2) Mocha 1 Link to comment Share on other sites More sharing options...
iamtheky Posted April 4, 2018 Share Posted April 4, 2018 (edited) for sport $str = "100.11 Q9" msgbox(0, '' , number($str) & " " & number(StringReverse($str))) edit: and i think you will find the official forums more useful and engaging than stackoverflow, but that is purely my biased opinion. Edited April 4, 2018 by iamtheky Mocha 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Mocha Posted April 8, 2018 Author Share Posted April 8, 2018 @abberration Hi abberration, yes, actually I have a string like whatever : whatsoever [100.11 Q9, c, 5] need to filter out to be a format like 100.11 9 only, but I have no idea how to do... and yes, there is a whitespace between 11 and 9 in the string. @Malkey Hi Malkey, thanks for giving me another answer to work out with and I really appreciate for your help. But I find out that if I tried to sort out them and filter them out from a string like whatever : whatsoever [100.11 Q9, c, 5], I'm still not able to do so, so far I have think of the following code below, however I still not getting the answer I want, would you please kindly help me again? Thank you... $strLine = "whatever : whatsoever [100.11 Q9, c, 5]" $sortString = StringRegExpReplace ($strLine, '[[:alpha:]\s\-\[\]]', "") $filterString = StringRegExp ($sortString,'([0-9]]{1,6})', $STR_REGEXPARRAYMATCH,1) MsgBox(0, "", $filterString) @iamtheky Hi iamtheky, thank you for showing your cool way to display and advise XD Link to comment Share on other sites More sharing options...
jchd Posted April 8, 2018 Share Posted April 8, 2018 Would this fit the bill? Local $strLine = "whatever : whatsoever [100.11 Q9, c, 5]" Local $filterString = StringRegExpReplace($strLine, ".*\[(\d+\.\d+\s)\D*(\d+).*", "$1$2") MsgBox(0, "", ">" & $filterString & "<") Mocha 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Mocha Posted April 8, 2018 Author Share Posted April 8, 2018 10 minutes ago, jchd said: Would this fit the bill? Local $strLine = "whatever : whatsoever [100.11 Q9, c, 5]" Local $filterString = StringRegExpReplace($strLine, ".*\[(\d+\.\d+\s)\D*(\d+).*", "$1$2") MsgBox(0, "", ">" & $filterString & "<") @jchdHey jchd, this perfectly works for me , thank you for helping! but would you mind please kindly teach me a bit how those syntaxes(pattern) work out in this case? Thank you so much tho...I know I still need to work on how RegExp work...but yeah...still struggling on that...Orz Link to comment Share on other sites More sharing options...
jchd Posted April 8, 2018 Share Posted April 8, 2018 I highly recommend you use http://regex101.com/ to try patterns and get a detailed explanation about their meaning. Also offers a debugging mode to see how things work step by step. Earthshine and Mocha 1 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Mocha Posted April 8, 2018 Author Share Posted April 8, 2018 thank you for offering the help jchd! I will definitely go to try it out this tool! Thank you so much!! 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