簡體   English   中英

PHP正則表達式獲取字符串中包含重復字符的單詞

[英]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

用於匹配3個以上重復字母的所有單詞的模式:

\b\w*(\w)\1{2}\w*

喜歡這個視頻。 這是awesooooommeee


https://regex101.com/r/cP7kT7/1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM