Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- From: sln@xxxxxxxxxxxxxxx
- Date: Thu, 08 Apr 2010 13:41:28 -0700
On Thu, 8 Apr 2010 17:22:48 +0200, Helmut Richter <hhr-m@xxxxxx> wrote:
On Thu, 8 Apr 2010, RedGrittyBrick wrote:
if ($x =~ /^[^:]*:?\bFOO$/) {
That will still independetly check for optional [^:]* and optional :
letting ,,,FOO pass. What you mean is probably /^([^:]+:)?\bFOO$/.
Here I assumed that the part before the colon is nonempty if the colon is
present.
this - /^([^:]+:)?\bFOO$/
Indeed, grouping the the optional [^:]* and optional :
into a ()? took care of [^:]* letting ,,,FOO pass
However, by doing that, you don't let "prefix.FOO" pass.
This is why he had the :? independently optional so that
^[^:]*:?\bFOO$ would match 'prefix.FOO'
The \b protects the '.FOO' and the 'FOO' at the same time.
where [^:]*:? specifically matches 'prefix:FOO' and just so
happens : is compliant with \b and redundant.
Grouping changes the condition. Now \b won't find '.FOO'
because the search never consumes a '.'
This /^([^:]+:)?\bFOO$/ regexp at best is bloviated and redundant,
at worst will not match the conditions.
-sln
.
- References:
- Perl 5.8 RE for fixed string with an optional colon terminated prefix
- From: RedGrittyBrick
- Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- From: RedGrittyBrick
- Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- From: Helmut Richter
- Perl 5.8 RE for fixed string with an optional colon terminated prefix
- Prev by Date: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- Next by Date: Re: FAQ 3.4 How do I find which modules are installed on my system?
- Previous by thread: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- Next by thread: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
- Index(es):