加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – 查找重复字符的单词

发布时间:2020-12-14 06:27:20 所属栏目:百科 来源:网络整理
导读:想要在字典中搜索在第二个和最后一个位置具有相同字符的每个单词,并在某个中间位置搜索一次. 例子: statement - has the "t" at the second,fourth and last placesevere = has "e" at 2,4,lastabbxb = "b" at 2,3,last 错误 abab = "b" only 2 times not 3
想要在字典中搜索在第二个和最后一个位置具有相同字符的每个单词,并在某个中间位置搜索一次.

例子:

statement - has the "t" at the second,fourth and last place
severe = has "e" at 2,4,last
abbxb = "b" at 2,3,last

错误

abab = "b" only 2 times not 3
abxxxbyyybzzzzb - "b" 4 times,not 3

我的grep无法正常工作

my @ok = grep { /^(.)(.)[^2]+(2)[^2]+(2)$/ } @wordlist;

例如该

perl -nle 'print if /^(.)(.)[^2]+(2)[^2]+(2)$/' < /usr/share/dict/words

打印例如

zarabanda

怎么了.

什么应该是正确的正则表达式?

编辑:

如何捕捉封闭的群体?例如为了

statement - want cantupre: st(a)t(emen)t - for the later use

my $w1 = $1; my w2 = $2; or something like...
这是应该适合您的正则表达式:
^.(.)(?=(?:.*?1){2})(?!(?:.*?1){3}).*?1$

现场演示:http://www.rubular.com/r/bEMgutE7t5

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读