[fpc-pascal] A Regular Expression failing on the borders of words

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Apr 10 15:33:06 CEST 2014


On Thu, 10 Apr 2014 10:05:44 -0300
luciano de souza <luchyanus at gmail.com> wrote:

> Well, I need to study more. I can't understand what is wrong. The
> match starts with a blank space: \s+. Some string follows: .*. And it
> ends in the border of word: \b. So, (\s+.*\b)*, for me, should return:
> +ABC +DEF. If "@" is not present, why the rest of the string was
> matched.

The last (\s+ at .*\b)* can be ignored, because of ()*.
The .* matches anything.
The \b matches any word border, for example the position behind 'Mary'.
So the (\s+\+.*\b) matches '+ABC +DEF @John @Mary'.

> [...]
> >> r.expression := '^(x\s+)*(\([A-E]\))*(\s*.*\.)+(\s+\+.*\b)*(\s+ at .*\b)*$';
> >> if r.exec('x (A) Write a report. +ABC +DEF @John @Mary') then

Mattias



More information about the fpc-pascal mailing list