Hi any regexp gurus out there? For converter I need a regexp that matches a string…
Show quoted text 7 lines
This would miss TIntLa and TIntaX
but I am sure it could be written in a cleaner way.
^Tnt(([^L]|.[^X]).+)
Show quoted text 5 lines
Mattias

Mailing lists / lazarus / 2010-06
11 messages · 8 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi any regexp gurus out there? For converter I need a regexp that matches a string…
This would miss TIntLa and TIntaX
but I am sure it could be written in a cleaner way.
^Tnt(([^L]|.[^X]).+)
Mattias
Hi
any regexp gurus out there?
For converter I need a regexp that matches a string starting with "Tnt", not followed by "LX" and captures everything after "Tnt". This actually works:
^Tnt([^L][^X].+)
but I am sure it could be written in a cleaner way.
Then there is another regexp that captures string after "TntLX":
^TntLX(.+)
and that is no problem.
Juha
On Tue, 15 Jun 2010 11:12:52 +0300 This would miss TIntLa and TIntaX ^Tnt(([^L]|.[^X]).+)…
> 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.
Does [^L]|.[^X] mean:
anything but 'L' or anything, followed by anything but 'X' ?
Juha
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$)
Mattias
Hmmm... It doesn't look very clean. It may be more correct but I am not sure of that.…
> > ^Tnt(([^L]|.[^X]).+) Hmmm... It doesn't look very clean.
I don't think *any* regex looks clean. ;-)
Graeme Geldenhuys wrote>> ^Tnt(([^L]|.[^X]).+) > Hmmm... It doesn't look very clean. I don't think *any* regex looks clean. ;-)
that because you aren't using the sandpaper on your eyeballs before studying the regex :P :lol:
On Tue, 15 Jun 2010 15:21:52 +0300 It is not very clean. It does not match TntL and TntL1.
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 ;-)
On Tue, 15 Jun 2010 15:21:52 +0300 It is not very clean. It does not match TntL and TntL1.
Even better regexp is: ^Tnt(([^L]|L[^X]).*|L$)
I wonder who will be able to understand and update such expressions, at any later time. To me it looks like typical write-only code :-(
DoDi
Hans-Peter Diettrich schrieb: > ^Tnt(([^L]|L[^X]).*|L$) I wonder who will be able to understand and update such expressions, at any later time. To me it looks like typical write-only code :-(
Yes, I also never got accustomed to regex syntax.
But I know that some are using it frequently.
And only then you will be able to manage such
special character monsters I think.
On Tue, 15 Jun 2010 15:21:52 +0300 It is not very clean. It does not match TntL and TntL1.
Even better regexp is: ^Tnt(([^L]|L[^X]).*|L$)
Thanks.
In this case even my original regexp may be good enough. There are always many characters following "LX". This was a corner case anyway when trying to convert Tnt* 3rd party components to LCL fall-back components.
The fall-back rules system now works nicely. Replacements and regexp rules can be added and they are stored in a config file.
Juha
I wonder who will be able to understand and update such expressions, at any later time.…
I'd wager that it's easier to understand than the equivalent pascal code that accomplishes the same function.
Henry