Regular expression question.

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
 
O

Oliver Sturm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regular expressions 20
regular expression 7
Regular Expression help 2
Regular Expression Help 1
Regular expression question 10
Regular Expression Question 4
Regular Expression question 3
Regular Expression Question 12

Top