C
Cloink
Can anyone tell me why my version of Perl won't compile a so-called
positive lookbehind assertion.
Specifically, I want to strip JavaScript comments from a file, so I'm
looking for "//" on a line, but since JS code can use regexes too,
it's possible to have "//" in a js-regex, which clearly isn't a
comment.
If the "//" is preceded by backslash however, i.e. "\//", I can be
pretty sure that this does NOT represent a comment. (I don't need
advice on when this rule might break - I have a very specific
purpose.)
Here's one piece of problematic (javascript) code
.split(/\//); // split string at forward-slash delimiters.
My PERL regex, in attempting to identify a preceding backslash in the
js code, I WANT to look like this
s/(?<[^\\])\/\/.*$//x
to identify two slashes on a line but not immediately preceded by a
backslash.
But the perl compiler tells me it doesn't understand:-
Sequence (?<[...) not recognized in regex; [line cont..]
marked by <-- HERE in m/(?<[ <-- HERE ^\\])//.*$/
Incidentally, if I replace the awkward "not-a-backslash" section of
the regex with a more simple "an x" section, I still get the same
compilation error, i.e.
replace "[^\\]" with "x"
"perl -v" tells me
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
and
Binary build 820 [274739] provided by ActiveState
http://www.ActiveState.com
Built Jan 23 2007 15:57:46
It's not my reference book that's wrong is it? (Perl in a Nutshell,
2nd Ed, June 2002, O'Reilly.)
Thanks.
positive lookbehind assertion.
Specifically, I want to strip JavaScript comments from a file, so I'm
looking for "//" on a line, but since JS code can use regexes too,
it's possible to have "//" in a js-regex, which clearly isn't a
comment.
If the "//" is preceded by backslash however, i.e. "\//", I can be
pretty sure that this does NOT represent a comment. (I don't need
advice on when this rule might break - I have a very specific
purpose.)
Here's one piece of problematic (javascript) code
.split(/\//); // split string at forward-slash delimiters.
My PERL regex, in attempting to identify a preceding backslash in the
js code, I WANT to look like this
s/(?<[^\\])\/\/.*$//x
to identify two slashes on a line but not immediately preceded by a
backslash.
But the perl compiler tells me it doesn't understand:-
Sequence (?<[...) not recognized in regex; [line cont..]
marked by <-- HERE in m/(?<[ <-- HERE ^\\])//.*$/
Incidentally, if I replace the awkward "not-a-backslash" section of
the regex with a more simple "an x" section, I still get the same
compilation error, i.e.
replace "[^\\]" with "x"
"perl -v" tells me
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
and
Binary build 820 [274739] provided by ActiveState
http://www.ActiveState.com
Built Jan 23 2007 15:57:46
It's not my reference book that's wrong is it? (Perl in a Nutshell,
2nd Ed, June 2002, O'Reilly.)
Thanks.