I came across an issue how to write Regex in the below case.
I want to match 4 alphabet letters. 1st letter can be any letter, 2nd letter is different letter from 1st letter, 3rd letter is the same as 2nd letter, and 4th letter is the same as 1st letter:
abba
deed
xyyx
However, it should not match 4 identical alphabet letters like:
aaaa
eeee
zzzz
I thought the following Regex would work, but Alteryx Designer throws an error. It seems some syntax error exist around [^\1] that I intended to specify "Not a letter captured at first position".
REGEX_Match([String], "^(\w)([^\1])\2\1$")
As a workaround, I had to modify the expression like this, and it worked.
REGEX_Match([String], "^(\w)(\w)\2\1$") and !REGEX_Match([String], "^(\w)\1{3}$")
Though I found workaround, I'm still wondering why my first Regex expression (\w)([^\1])\2\1 had a syntax error, and how should I re-write it keeping a single Regex expression without AND/OR operator? If you could advise on this, it would be appreciated.
Solved! Go to Solution.
@gawa similar to @flying008 solution
In Alteryx, backslashes are used as escape characters in regular expressions, and you might need to double-escape them. Try using four backslashes before digit reference \1
Thank you very much, I didn't know "Negative Lookahead" so it's a really good learning for me.
Positive Lookahead (?=pattern)
Negative Lookahead (?!pattern)
There remains a lot to learn on Regex for me. Thank you again!