Jump to content

StringRegExpReplace Replace a letter if the previous char was a digit


 Share

Recommended Posts

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 by Qwerty212
Link to comment
Share on other sites

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 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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...