It is currently April 20th, 2024, 5:04 am

Regex replace in one pass

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7128
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Regex replace in one pass

Post by Yincognito »

Suppose I have a string like: jsmorley is a smart guy (see what I just did here? :sly: ) in a measure, and I want to replace every letter with its alphabetical index (e.g. a->1, b->2 and so on), I would do like this:

Code: Select all

RegExpSubstitute=1
Substitute="a":"1","b":"2",...and so forth
...but this is running through the string 26 times (once for every letter in the alphabet) just to replace a single letter globally (in this case), which might be overkill from a performance point of view if you have to do a lot of (different) replacements. Is there a way to do this in a single regex pass through the whole string? That is, running through the string a single time, and replace letters as the regex advances through the string. Like I think it seems to be done here, in the first piece of code (this is in Python, not in C++ though).

In other words, is there a way to "concatenate" or "join" multiple regex substitutions in a single big regex substitution that achieves the same result? If not, is this an easy to implement thing in a potentially new option in Rainmeter measures?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth