想要在字典中搜索在第二个和最后一个位置具有相同字符的每个单词,并在某个中间位置搜索一次.
例子:
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$