简体   繁体   English

8 或 7 个字符的正则表达式

[英]regular expression for words with 8 or 7 characters

I'm looking for a regular expression that matches words with 8 or 7 characters and includes (ea).我正在寻找一个匹配 8 或 7 个字符的单词并包含 (ea) 的正则表达式。 this is what I've got so far:这是我到目前为止所得到的:

[\w*(ea)\w*]{7,8}

the problem is it also accepts the first 8 characters of "bbeabbbbbbb" but I dont want that.问题是它也接受“bbeabbbbbbb”的前 8 个字符,但我不想要那个。

when inside charset [] , brackets ( , ) loses its special meaning and matched literally.当在字符集[] ,方括号( , )失去其特殊含义并按字面​​匹配。 that's why you are getting wrong results.这就是为什么你得到错误的结果。 Try below regex.试试下面的正则表达式。

(?=(?=(?<!\w)\w*\(ea\))[\w()]{7,8}(?:\s|$))[\w()]{7,8}

Demo in regex101.com regex101.com 中的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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