[Lazarus] Regexp syntax

Alexander Klenin klenin at gmail.com
Tue Jun 15 18:42:43 CEST 2010


On Tue, Jun 15, 2010 at 23:55, Mattias Gaertner
<nc-gaertnma at netcologne.de> wrote:
> On Tue, 15 Jun 2010 15:21:52 +0300
> Juha Manninen <juha.manninen at phnet.fi> wrote:
>
>> > > but I am sure it could be written in a cleaner way.
>> >
>> > ^Tnt(([^L]|.[^X]).+)
>>
>> Hmmm... It doesn't look very clean. It may be more correct but I am not sure
>> of that.
>
> It is not very clean. It does not match TntL and TntL1.
>
>
>> Does  [^L]|.[^X]  mean:
>> anything but 'L' or anything, followed by anything but 'X' ?
>
> The pipe is like an 'or' operator. [^L]|.[^X] means:
> Any character but L OR any character followed by any character but X.
> It matches a, b, La, Lb, but not LX and not L.
>
> Even better regexp is:
>
> ^Tnt(([^L]|L[^X]).*|L$)

The correct (and clean) answer is actually:
^Tnt(?!LX)(.+)$

Sadly, assertions are poorly supported by many languages/libraries.
Use Perl if you want the full power of regexps ;-)

-- 
Alexander S. Klenin




More information about the Lazarus mailing list