Qwerty212 Posted December 30, 2019 Share Posted December 30, 2019 (edited) Hello from Barcelona. I have a doubt about StringRegExpReplace I'm populating some listviews with the results of a SQL Query and one of the strings can look like this: "Bimate, 8-15M + . Mesh." I want to change the M that I have marked in Bold font with this symbol: µ The rule to know wich M I want to change is that it will always has a digit in the previous char. I have tried _GUICtrlListView_AddSubItem($listview, $n, StringReplace($query[$n][$s], "M", "µ", 0, 1), $s) But, it also changes the second M (The one from "Mesh.") I have tried searching for the capital M position in the string, but it can happen that the original string ends with a M ("Bimate, 8-15M") The only reliable pattern for the current querys and for unknow future ones is that the "M" that I need to change is always preceded by a digit. Any help would be trully appreciated. Edited December 30, 2019 by Qwerty212 Link to comment Share on other sites More sharing options...
jchd Posted December 30, 2019 Share Posted December 30, 2019 (edited) Try this: _GUICtrlListView_AddSubItem($listview, $n, StringReplace($query[$n][$s], "(?<=\d)M", "µ", 0, 1), $s) The sequence (?<=\d) is a look-behind assertion. In plain English, it means: "what follows [here the letter M] must be immediately preceded by one digit". See the help about StringRegExp function. Edited December 31, 2019 by jchd Typo fixed in text. 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...
pixelsearch Posted December 30, 2019 Share Posted December 30, 2019 (edited) @jchd $res = StringRegExpReplace("Bimate, 8-15M + .Mesh", "(?<=\d)M", "µ") $res = StringRegExpReplace("Bimate, 8-15M + .Mesh", "(\d)M", "$1µ") To improve my little knowledge about RegExp, could you please confirm that both solutions are strictly equivalent ? Thanks Edited December 30, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
mikell Posted December 31, 2019 Share Posted December 31, 2019 9 hours ago, jchd said: The sequence (?<=\D) ... means: "what follows ... must be immediately preceded by one digit" Warning , typo inside @pixelsearch Both solutions work but I personally prefer the first one because it matches the requirement strictly pixelsearch 1 Link to comment Share on other sites More sharing options...
jguinch Posted December 31, 2019 Share Posted December 31, 2019 personally , I prefer to use \K instead of the lookbehind method when possible, because a lookbehind expression cannot be used with non-fixed length of characters Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted December 31, 2019 Share Posted December 31, 2019 Typo fixed, sorry for that mistake. 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...
Qwerty212 Posted January 1, 2020 Author Share Posted January 1, 2020 Thanks a lot to you all for the help!! 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