Tuesday, 15 May 2012

php - REGEX - match words that contain letters repeating next to each other -



php - REGEX - match words that contain letters repeating next to each other -

im looking regex matches words repeat letter(s) more 1 time , next each other.

here's example:

this exxxmaple oooonnnnllllyyyyy!

by far havent found can match:

exxxmaple , oooonnnnllllyyyyy

i need find , place them in array, this:

preg_match_all('/\b(???)\b/', $str, $arr) );

can explain regexp have use?

you can utilize simple regex like

\s*(\w)(?=\1+)\s*

see how regex matches @ http://regex101.com/r/rf3pr7/3

\s matches other space

* quantifier, 0 or more occurance of \s

(\w) matches single character, captures in \1

(?=\1+) postive ahead. asserts captrued character followed itsef \1

+ quantifiers, 1 or more occurence of repeated character

\s* matches other space

edit

if repeating must more once, slight modification of regex trick

\s*(\w)(?=\1{2,})\s*

for illustration http://regex101.com/r/rf3pr7/5

php regex

No comments:

Post a Comment