Regular expression question.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to compose a couple of regular expressions that:
1. Detects an occurance of more than two consecutive characters that are the
same, for example, from the string "abbcdddefGGGh" I want it to find the
"ddd" and "GGG".
2. Detects any repeating sequences of characters, for example, from the
string "abcddefcddhij" I want it to find "cdd".

I have spent ages trying to work these out but with no success. Can anyone
shed some light on these?

Many thanks in advance.
Steve
 
Steve said:
I am trying to compose a couple of regular expressions that:
1. Detects an occurance of more than two consecutive characters that are the
same, for example, from the string "abbcdddefGGGh" I want it to find the
"ddd" and "GGG".
(.)\1{2,}

2. Detects any repeating sequences of characters, for example, from the
string "abcddefcddhij" I want it to find "cdd".

(?<string>.+).*\k<string>

Look at the capture group "string" for the match.



Oliver Sturm
 
Back
Top