Home > Archive > PERL Beginners > November 2005 > Error : Nested quantifiers before HERE mark in regex
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Error : Nested quantifiers before HERE mark in regex
|
|
| Bedanta Bordoloi 2005-11-29, 3:56 am |
| Hi All,
I'm using the following regex in my code with processes a log file
$str =~ s/(^$log_entry[0]\s)//i
But I'm getting the following error on running the script:
Nested quantifiers before HERE mark in regex m/(^img13.** << HERE **\s)/
Can the regex be written in some other way? Please help.
Thanks,
Bedanta
| |
| Xavier Noria 2005-11-29, 3:56 am |
| On Nov 29, 2005, at 10:22, Bedanta Bordoloi, Gurgaon wrote:
> Hi All,
>
> I'm using the following regex in my code with processes a log file
>
> $str =~ s/(^$log_entry[0]\s)//i
>
> But I'm getting the following error on running the script:
>
> Nested quantifiers before HERE mark in regex m/(^img13.** << HERE **
> \s)/
Is $log_entry[0] supposed to be a regexp?
-- fxn
| |
| Bedanta Bordoloi 2005-11-29, 3:56 am |
| No, $log_entry[0] holds a string, and we are getting the error as ** is a
part of that string.
Bedanta
-----Original Message-----
From: Xavier Noria [mailto:fxn@hashref.com]
Sent: Tuesday, November 29, 2005 3:08 PM
To: beginners perl
Subject: Re: Error : Nested quantifiers before HERE mark in regex
On Nov 29, 2005, at 10:22, Bedanta Bordoloi, Gurgaon wrote:
> Hi All,
>
> I'm using the following regex in my code with processes a log file
>
> $str =~ s/(^$log_entry[0]\s)//i
>
> But I'm getting the following error on running the script:
>
> Nested quantifiers before HERE mark in regex m/(^img13.** << HERE **
> \s)/
Is $log_entry[0] supposed to be a regexp?
-- fxn
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| John W. Krahn 2005-11-29, 7:56 am |
| Bedanta Bordoloi, Gurgaon wrote:
> Hi All,
Hello,
> I'm using the following regex in my code with processes a log file
>
> $str =~ s/(^$log_entry[0]\s)//i
>
> But I'm getting the following error on running the script:
>
> Nested quantifiers before HERE mark in regex m/(^img13.** << HERE **\s)/
>
> Can the regex be written in some other way? Please help.
$str =~ s/(^\Q$log_entry[0]\E\s)//i
John
--
use Perl;
program
fulfillment
| |
| Bedanta Bordoloi 2005-11-29, 7:56 am |
| Thanks, John for that, it works fine now...
Bedanta
-----Original Message-----
From: John W. Krahn [mailto:krahnj@telus.net]
Sent: Tuesday, November 29, 2005 3:25 PM
To: Perl Beginners
Subject: Re: Error : Nested quantifiers before HERE mark in regex
Bedanta Bordoloi, Gurgaon wrote:
> Hi All,
Hello,
> I'm using the following regex in my code with processes a log file
>
> $str =~ s/(^$log_entry[0]\s)//i
>
> But I'm getting the following error on running the script:
>
> Nested quantifiers before HERE mark in regex m/(^img13.** << HERE **\s)/
>
> Can the regex be written in some other way? Please help.
$str =~ s/(^\Q$log_entry[0]\E\s)//i
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Xavier Noria 2005-11-29, 7:56 am |
| On Nov 29, 2005, at 10:42, Bedanta Bordoloi, Gurgaon wrote:
> No, $log_entry[0] holds a string, and we are getting the error as
> ** is a
> part of that string.
Interpolation in regexps is done before the regexp is interpreted as
such. For instance, if $foo is "*" and we have
/.*$foo/
first interpolation is done giving
/.**/
and that is interpreted as a regexp, which in this case is invalid
and would raise an error.
In consequence, metacharacters in interpolated strings need to be
escaped to be treated literally, and this is easy to get:
$str =~ s/(^\Q$log_entry[0]\E\s)//i
There we start escaping with \Q, and end it with \E, so that "\s)" is
interpreted as part of the regexp as is. If you wanted to escape the
very string outside the regexp there's quotemeta().
-- fxn
|
|
|
|
|