Mark Kremer
6/1/2009 7:52:00 AM
I'm not sure if you still want the regex, but following regex should do
the trick: ^(.{1})(?!\1)(.{1})(?!\1|\2).{1}\2$
Harry Kakueki wrote:
> I want to write a regular expression to do the following.
>
> The first character can be any character.
> The second character can be anything except the first character.
> The third character can be anything except the first two characters.
> (This is a problem. There may be other problems.)
> The fourth character is the same as the second character.
>
> st = "abcb"
> p st =~ /^(.)([^\1])([^\1\2])(\2)$/ # I expected a match
>
> uv = "abbb"
> p uv =~ /^(.)([^\1])([^\1\2])(\2)$/ # I did not expect a match
>
>
> They both match.
> How can I write the regular expression?
> Somehow I have the syntax wrong.
>
>
>
> Harry
>
>