Chimp 715 Posted July 26, 2019 hello to all how can I clean a string from unwanted chars and keep only chars belonging in the range from asc(32) to asc(127) inclusive and replace all other chars that falls outside that range with another char (a space chr(32) for example) in one shot, using a regular expression? (or whatever else but looping...) example the string: "Hello ☺ «everybody» Love ♥ and peace" should result as "Hello everybody Love and peace" thanks on advance for helping small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites
Danp2 909 Posted July 26, 2019 Try this -- #include <MsgBoxConstants.au3> Test1() ; This example demonstrates a basic replacement. It replaces the vowels aeiou ; with the @ character. Func Test1() Local $sInput = "Hello ☺ «everybody» Love ♥ and peace" Local $sOutput = StringRegExpReplace($sInput, "[^\x00-\x7F]+", " ") Display($sInput, $sOutput) EndFunc ;==>Test1 Func Display($sInput, $sOutput) ; Format the output. Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox($MB_SYSTEMMODAL, "Results", $sMsg) EndFunc ;==>Display 2 Chimp and iamtheky reacted to this [UDF] WebDriver Latest version Wiki FAQs Share this post Link to post Share on other sites
Chimp 715 Posted July 26, 2019 👌It seems to work well Thanks a lot Dan small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites
Chimp 715 Posted July 26, 2019 (edited) @Danp2, hemmm, sorry, I talked too quickly, that pattern has issues, it doesn't remoove chars below chr(32) and above chr(127)... try this to see the issue: #include <MsgBoxConstants.au3> Test1() ; This example demonstrates a basic replacement. It replaces the vowels aeiou ; with the @ character. Func Test1() Local $sInput = "Hello ☺ " & @CR & "«everybody» Love ♥ " & ChrW(512) & " and peace" Local $sOutput = StringRegExpReplace($sInput, "[^\x00-\x7F]+", " ") Display($sInput, $sOutput) EndFunc ;==>Test1 Func Display($sInput, $sOutput) ; Format the output. Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox($MB_SYSTEMMODAL, "Results", $sMsg) EndFunc ;==>Display Edited July 26, 2019 by Chimp it's ok for chars above 127 small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites
Danp2 909 Posted July 26, 2019 So... just modify it accordingly. Try this instead -- Local $sOutput = StringRegExpReplace($sInput, "[^\x20-\x7F]+", " ") 1 Chimp reacted to this [UDF] WebDriver Latest version Wiki FAQs Share this post Link to post Share on other sites
Chimp 715 Posted July 26, 2019 ah yes, sorry, it was so easy to correct it ... I was almost near to correct it myself too. Thanks again (damn regexp ) 1 Danp2 reacted to this small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites