Discussion:
Why this RegExp is not working on TCL 8.5?
(too old to reply)
Ahmad
2009-07-30 11:34:09 UTC
Permalink
Hi,

I was trying pieces of regular expressions testing on tclsh, when I
came to this behaviour; I did the following sequence:

% set a {aaaAAAaaa}
aaaAAAaaa
% regexp (?i)AAA(?-i:AAA)AAA $a
couldn't compile regular expression pattern: quantifier operand
invalid

Tried it also between braces delimits:

% regexp {(?i)AAA(?-i:AAA)AAA} $a
couldn't compile regular expression pattern: quantifier operand
invalid

I'm using TCL 8.5 under Linux OS.

% puts $tcl_version
8.5

Why this error happens?

I was trying to do case insensitive matching for a pattern, followed
by a case sensitive matching (within the look ahead scope), finally
ended by a case insensitive matching. Did i make anything wrong?
Please help.

Thanks,
Ahmad
Glenn Jackman
2009-07-30 11:50:53 UTC
Permalink
Post by Ahmad
% set a {aaaAAAaaa}
aaaAAAaaa
% regexp (?i)AAA(?-i:AAA)AAA $a
couldn't compile regular expression pattern: quantifier operand
invalid
[...]
Post by Ahmad
I was trying to do case insensitive matching for a pattern, followed
by a case sensitive matching (within the look ahead scope), finally
ended by a case insensitive matching. Did i make anything wrong?
The re_syntax man page (section METASYNTAX) says (emphasis mine):

An ARE may *begin with* embedded options: a sequence (?xyz) [...]
specifies options affecting the rest of the RE.

If you specify (?i) at the start of your regex, the whole thing will be
insensitive. Metasyntax in the middle is considered only as atoms and
quantifiers, and the second ? does not follow an atom.

You achieve your goal, you may have to resort to:

regexp {[aA]{3}AAA[aA]{3}} $a
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Loading...