[Linux-disciples] A regex question

Stephen R Laniel linux-disciples@bostoncoop.net
Wed, 28 Jan 2004 19:07:50 -0500


I'm looking to write a regex that says "Find me any character
(which we'll remember as $1), followed by any number of other
characters which can be anything except for $1, followed by $1
again, followed by a literal bracket, a string from a given set
of strings, and a closing bracket." The regex I've tried to use
for this is

(.)([^$1]*)$1\[$sourceKey\]

I don't think Perl likes the [^$1] syntax very much; it's
complaining whenever I run this script.

I've also tried using minimal matching, viz.

(.)(.*?)$1\[$sourceKey\]

but for some reason the second occurrence of $1 seems to get
caught inside of $2.

Any idea what I'm doing wrong?

-- 
``You will see light in the darkness
  You will make some sense of this''
 -The Police, "Secret Journey"