zemane has asked for the wisdom of the Perl Monks concerning the following question:
I want to create a regex object that can be used to match zero or more VHDL comments. A VHDL comment starts with '--' and continues until the end of the line or file.
I want to use $c with different quantifiers, like $c, $c?, $c+ and $c*, depending on context.my $c = qr/(?>--[^\n]*(?:\n|\z))/; # VHDL comment regex
I want the following code to match at positions 2-9:# position 01234567 89 my $str = "a --b x\n x";
But the following should not match at all:$str =~ m/$c* x/;
Unfortunately, when the regex fails to match 'x' the engine bumps along to a position inside the comment (which I'd like to skip) and eventually matches at position 6.$str =~ m/$c*x/;
Any idea how to fix this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I avoid regex engine bumping along inside an atomic pattern?
by tilly (Archbishop) on Aug 23, 2008 at 04:31 UTC | |
by zemane (Novice) on Aug 24, 2008 at 16:55 UTC | |
by tilly (Archbishop) on Aug 24, 2008 at 18:54 UTC | |
|
Re: How do I avoid regex engine bumping along inside an atomic pattern?
by toolic (Bishop) on Aug 23, 2008 at 02:18 UTC | |
|
Re: How do I avoid regex engine bumping along inside an atomic pattern?
by jethro (Monsignor) on Aug 23, 2008 at 02:18 UTC | |
|
Re: How do I avoid regex engine bumping along inside an atomic pattern?
by AnomalousMonk (Archbishop) on Aug 23, 2008 at 03:36 UTC |