Re: Error : Nested quantifiers before HERE mark in regex
- From: fxn@xxxxxxxxxxx (Xavier Noria)
- Date: Tue, 29 Nov 2005 11:06:06 +0100
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 .
- References:
- RE: Error : Nested quantifiers before HERE mark in regex
- From: Bedanta Bordoloi
- RE: Error : Nested quantifiers before HERE mark in regex
- Prev by Date: RE: Error : Nested quantifiers before HERE mark in regex
- Next by Date: Re: help about regex matching
- Previous by thread: RE: Error : Nested quantifiers before HERE mark in regex
- Next by thread: RE: Error : Nested quantifiers before HERE mark in regex
- Index(es):
Relevant Pages
|
|