Re: [Clip] Re: Search and Replace and increment number at the same time
- Alec Burgess wrote:
> flo.gehrke (flo.gehrke@...) wrote (in part) (on 2009-10-11 atPCRE seeks backward from its "bump-along" starting point for a
>> --- In firstname.lastname@example.org, Alec Burgess <buralex@...> wrote:
>> > I've seen you (Sheri) and Flo use the \K construct before w/o
>> > ever really understanding exactly how it worked.
>> > Now that I know what the \K does, is there any difference between
>> > two (other than the simplicity of \K)
>> As you you wrote, \K is similar to a Lookbehind Assertion. So
>> (?<=Look)behind matches 'Lookbehind' without consuming the 'Look'.
>> Look\Kbehind has the same effect.
>> The difference is that the Lookbehind demands a fixed lenghth of the
>> pattern whereas \K works with any length. That's why I often prefer
>> For example: (?<=\w+)behind produces an Error Message "Regex error:
>> lookbehind assertion is not of fixed length." In contrast to that,
>> \w+\Kbehind works fine.
> Fixed length limitations in lookbehinds rang a bell when you mentioned
> it. When I check with RegexBuddy I see that it fails with its (somewhat
> old implementation of PCRE) but works with the JGSoft flavor (ie. Jan's
> "superset" version of ALL regex flavors) and also with .NET flavor but
> fails in most of the rest. For those that fail its indicated by marking
> the "+" in RED.
> I'm not sure if any future version of PCRE (and hence when supported by
> Eric) Notetab will support this. I'll try to remember the key
> distinction wrt. to \K when I write clips. Thanks for the followup info
> (and Don for the question!).
The fixed length requirement will never change; however it is
permissible to have alternates of varying lengths within a look-behind.
In order to achieve the same match using \K instead of a look-behind
assertion, the bump-along position is at the beginning of the would-be
look-behind. So while the results are similar, the processing differs.