Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1597

Help: Rainmeter Skins • Re: Regexpsubstitute doesn't work the way I need it to.

$
0
0
Just so it's clear why that happened: since ".*:(\d+):.*" doesn't have any kind of "anchor" at the beginning or end to know from where and to where to do the substitute, it does it everywhere (i.e. on each match) in the string, that's why the former attempt didn't succeed as desired. Generally speaking, it's almost mandatory to use some kind of anchor to "lock" the pattern to a certain area of the string if you need to substitute only one occurrence and not all, that's why balala's suggestion worked (that and the ?U ungreedy flag to match as few chars as possible with the * quantifier, of course).

By the way, it's not often used, but a ? after the first * quantifier, to make the pattern "^.*?:(\d+):.*$" has the same effect as using the ?U flag here. What ? does after a quantifier is to locally "invert the greediness" (or lack of, if ?U is used) set by the presence or absence of ?U. The ? acts locally where used, while ?U acts globally on the entire string.

Statistics: Posted by Yincognito — Yesterday, 9:37 pm



Viewing all articles
Browse latest Browse all 1597

Trending Articles