Mingre Posted July 25, 2015 Share Posted July 25, 2015 (edited) Local $sVar = 'fsdf\\x\\dsadsad\das\/' ConsoleWrite($sVar & @CRLF ) Consolewrite(StringRegExpReplace($sVar, '[^(\\.)]', ' '))Hello forums,How do I replace with spaces all characters except for those that match the regexp \\. (which matches backslash followed by any character).I've tried the above code but it doesn't work properly.Thank you!Edit1: Please see posts #7 and 8 for more details.Edit2: Solved!See Post#9 by jchd. Add #include <string.au3> to the code. Edited July 25, 2015 by Mingre Add 'solved' to title. Link to comment Share on other sites More sharing options...
jchd Posted July 25, 2015 Share Posted July 25, 2015 Like this:Local $sVar = 'fsdf\\x\\dsadsad\das\/' ConsoleWrite($sVar & @LF) Consolewrite(StringRegExpReplace($sVar, '(\\.)', ' ') & @LF) 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...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 Thanks jchd for the response! What I'd like to do tho is to replace only those that do not match the regexp (\\.) Link to comment Share on other sites More sharing options...
SadBunny Posted July 25, 2015 Share Posted July 25, 2015 Can you specify what you would expect exactly (including leading/trailing spaces etc.) to be the output of the example? Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
SadBunny Posted July 25, 2015 Share Posted July 25, 2015 (edited) Note that your current regexp means:/[^(\\.)]/ [^(\\.)] match a single character not present in the list below( the literal character (\\ matches the character \ literally.) a single character in the list .) literally(I used regex101.com.)Note that if you reformulate your question, you end up with a requirement of changing any character that does not match a combination of two characters. That doesn't fit. Edited July 25, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 Local $sText= 'fsdf\\x\\dsadsad\das\/' Local $sVar = 'fsdf\\x\\dsadsad\das\/' ConsoleWrite($sVar & @CRLF ) $x = StringRegExp($sVar, '(\\.)',3) Local $sNew = '', $iCount For $element In $x $iCount = StringInStr($sVar, $element) ;ConsoleWrite($element & ' <' & $iCount & '>' & @LF) $sVar = StringTrimLeft($sVar, $iCount + 1) ;MsgBox(0, $sText, $sVar) $sNew &= StringFormat('%' & $iCount + 1 & 's', $element) NExt ConsoleWrite($sNew & @LF)Hello again, basically what I wanted to get is a shorter version of the above code. Link to comment Share on other sites More sharing options...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 Hello sadbunny, sorry for not being clear.I would like line 1 to turn into line 2 with just stringregexpreplace. fsdf\\x\\dsadsad\das\/ \\ \\ \d \/ Link to comment Share on other sites More sharing options...
SadBunny Posted July 25, 2015 Share Posted July 25, 2015 (edited) So basically you want to replace any character that is not part of the regex \\. unless it is also a combination of the regex \\\\. ? Because you want to keep the d in \d, but not the x in \\x or the d in \\d.Hmmz... I wouldn't know a regex for that. Hopefully someone else does. Edited July 25, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
jchd Posted July 25, 2015 Share Posted July 25, 2015 Sorry I misread the OP. Try this:Local $sVar = 'fsdf\\x\\dsadsad\das\/xyz\u\w' ConsoleWrite($sVar & @LF) Local $sOut = Execute(StringRegExpReplace($sVar, '([^\\]+)((?:\\.)*)', '_StringRepeat(" ", StringLen("$1")) & "$2" & ') & '""') ConsoleWrite($sOut & @LF) 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...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 SadBunny, no prob. Thank you anyway!jhcd, it returns an empty string. Link to comment Share on other sites More sharing options...
jchd Posted July 25, 2015 Share Posted July 25, 2015 (edited) No. Edited July 25, 2015 by jchd 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...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 Sorry but It does in my PC. (Please see attached file.) empty.bmp Link to comment Share on other sites More sharing options...
jchd Posted July 25, 2015 Share Posted July 25, 2015 Looks like you miss this:#include <String.au3> 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...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 Looks like you miss this:#include <String.au3> It works perfectly now! Thanks! Link to comment Share on other sites More sharing options...
mikell Posted July 25, 2015 Share Posted July 25, 2015 jc, is this one good ?Local $sOut = StringRegExpReplace($sVar, '(?<=^|\\\\|[^\\])[^\\]', " ") Link to comment Share on other sites More sharing options...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 (edited) jc, is this one good ?Local $sOut = StringRegExpReplace($sVar, '(?<=^|\\\\|[^\\])[^\\]', " ") Hello mikell, yours works perfectly too. And I like its simplicity Would you be so kind to explain how the first '^' works? I don't quite get it. Thanks!Edit1: Nevermind, just found out how it works Edit2:Apparently,while testing both codes, they didn't work well when the string tested was '\\\a' (which turned '\\\ ') Edited July 25, 2015 by Mingre Link to comment Share on other sites More sharing options...
mikell Posted July 25, 2015 Share Posted July 25, 2015 Apparently,while testing both codes, they didn't work well when the string tested was '\\\a' (which turned '\\\ ')What should be the return for '\\\a' ? Link to comment Share on other sites More sharing options...
Mingre Posted July 25, 2015 Author Share Posted July 25, 2015 \\\a should still return \\\a, but both codes return '\\\ '. Link to comment Share on other sites More sharing options...
jchd Posted July 25, 2015 Share Posted July 25, 2015 Ah, sorry escape at the head need this:#include <String.au3> Local $sVar = '\\\a\bdfsdf\\x\\dsadsad\das\/xyz\u\w' ConsoleWrite($sVar & @LF) Local $sOut = Execute(StringRegExpReplace($sVar, '([^\\]*?)((?:\\.)*)', '_StringRepeat(" ", StringLen("$1")) & "$2" & ') & '""') ConsoleWrite($sOut & @LF) 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...
mikell Posted July 25, 2015 Share Posted July 25, 2015 (edited) #include <String.au3> $sVar = "000\a\aa\\bbb\\\ccc\\\\ddd\\\\\eee\\\\\\fff\\\\\\\ggg" ;expected result: ...\a\a.\\...\\\c..\\\\....\\\\\e..\\\\\\...\\\\\\\\g.. Local $sOut1 = Execute(StringRegExpReplace($sVar, '([^\\]*?)((?:\\.)*)', '_StringRepeat(".", StringLen("$1")) & "$2" & ') & '""') Local $sOut2 = StringRegExpReplace($sVar, '(((?<=^|[^\\])(?:\\\\)+)|()(?<=^|[^\\]))[^\\]', "$2.") Msgbox(0,"", $sVar & @crlf & $sOut1 & @crlf& $sOut2) Edited July 25, 2015 by mikell 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