S
stenor
I'd appreciate some help from a regex guru with this:
I'm trying to match a pattern that looks more or less like this:
<string1><statictext><string2>
where string1 and string2 are not the same. I need to do this in a
single regex (rather than capturing $1 and $2 and comparing after the
fact.
I've tried this as a test (in this case <statictext> is just
whitespace:
/(\w+)\s+(?!\1)/
This will match "foo bar" as expected, but it also matches "foo foo"
which it ought not to.
Using positive lookahead had the expected result:
/(\w+)\s+(?=\1)/ matches "foo foo" but not "foo bar", which is the
intended behavior.
Any ideas regarding why using the negative lookahead assertion as I've
done doesn't do what I'd like it to do? And/or how to do it correctly?
email cc appreciated.
Thanks,
Scott
I'm trying to match a pattern that looks more or less like this:
<string1><statictext><string2>
where string1 and string2 are not the same. I need to do this in a
single regex (rather than capturing $1 and $2 and comparing after the
fact.
I've tried this as a test (in this case <statictext> is just
whitespace:
/(\w+)\s+(?!\1)/
This will match "foo bar" as expected, but it also matches "foo foo"
which it ought not to.
Using positive lookahead had the expected result:
/(\w+)\s+(?=\1)/ matches "foo foo" but not "foo bar", which is the
intended behavior.
Any ideas regarding why using the negative lookahead assertion as I've
done doesn't do what I'd like it to do? And/or how to do it correctly?
email cc appreciated.
Thanks,
Scott