简体   繁体   中英

Regular expressions for removing repeated letters with spaces in java

I need some help understanding regular expressions please. I'm trying to build some chat filters to remove spam.

So far I have (?<!'|\\w|\\s)(^[az]$)(?!\\w|\\s) which will remove 'a'

and (?<!'|\\w|\\s)(.)\\1{3,}(?!\\w|\\s) which will catch 'aaaa'

Where I need help is finding one that will catch 'aaaaaaaaaaa a'

Can some please steer me in the correct direction? Thank you very much.

根据上面的评论,此模式应该是您要寻找的:

^(.+?) ?(?>(?:\\1| )+)$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM