[英]PHP Regular expression to get words with repeated chars in a string
我試圖用重復的字符將字符串中的單詞。 例如:“我不喜歡這部影片。這是awesooooommeee。”
如何獲得結果:loooovve awesooooommeee?
您可以將此正則表達式與反向引用一起使用:
\b\w*(\w)\1\w*
正則表達式分解:
\b # word boundary
\w* # match 0 or more word characters
(\w) # match a single word char and capture it as group #1
\1 # back-reference to captured group #1 to make sure we have a *repeat*
\w* # match 0 or more word characters
順便說一句,它也將與II
匹配II
因為它具有重復字符I
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.