Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-04

regex unit and word boundaries

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ben Smith

Hi,

Does the Regex unit included with FCL support word boundaries? eg: the \b tag as used by some other regex libraries. If the Regex unit does support it, what syntax must I use?

I know about the ^ (beginning of line) and $ (for end of line), but that is not what I'm looking for, because the words I want to match might appear in the middle of the text.

              Ben.

Reply by email

ik
to Ben Smith
Ben Smith wrote 10 lines
Hi, Does the Regex unit included with FCL support word boundaries? eg: the \b tag as used by some other regex libraries. If the Regex unit does support it, what syntax must I use? I know about the ^ (beginning of line) and $ (for end of line), but that is not what I'm looking for, because the words I want to match might appear in the middle of the text.

What's wrong with /a word/ (without the slash) ?
But if the word can exists in a middle of a text, and you do not look for a pattern, then regex is not what you should use, but "pos" instead. Because pos is more efficient then regex.

Show quoted text 8 lines
-- Ben. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il

Reply by email

Ben Smith
to ik
ik wrote
What's wrong with /a word/ (without the slash) ?

Sorry, I don't understand.

But if the word can exists in a middle of a text, and you do not look for a pattern, then regex is not what you should use, but "pos" instead. Because pos is more efficient then regex.

I'm implementing syntax highlighting in one of my text edit components. I am using regex to find keywords, reserved words etc to highlight.

So when I search for 'class', it must not match 'Classes', so I can't use something as rudimentary as Pos().

Normally you enable word boundaries in your regex as follows, to accomplish what I need:

\b(class|record|begin|end)\b

alternatively (if \b is not available) I can do something like....

^\s*end;?\s*$

which will match 'end;' and 'end' but not something like 'amend'

But alas, it seems the FCL regex unit doesn't have \s (any whitespace chars) implemented either. It seems the FCL regex unit is in its infancy, and I need a more feature complete implementation of regex.

I did some Google'ing and TRegExpr class library by Andrey V. Sorokin seems a lot more feature complete and free. I will probably have to switch to using that component. A shame really, because I like to stick to using units included with FPC. Doing some more searching, I believe Lazarus IDE also uses the TRegExpr unit, instead of FCL's one.

Is anybody still working on the FCL regex unit? Are there plans to implement any more regex features, or is that unit abandon-ware. Can't the FPC developers include TRegexpr library as part of FCL? It will save them a lot of development effort.

              Ben.

Reply by email