开发者

Position pattern matching

开发者 https://www.devze.com 2023-02-07 00:44 出处:网络
I want to look through a list of words and find any that match the pattern of ABCCDAA. How can I do this? Th开发者_如何学Pythonat is, find any words of length 7 whose letters correspond to that patter

I want to look through a list of words and find any that match the pattern of ABCCDAA. How can I do this? Th开发者_如何学Pythonat is, find any words of length 7 whose letters correspond to that pattern (first and last two letters are X, etc).


regex is simple enough -

/^([a-zA-Z])([a-zA-Z])([a-zA-Z])\3([a-zA-Z])\1\1$/


Here's my solution:

([a-zA-Z]).([a-zA-Z])\2.\1\1
0

精彩评论

暂无评论...
验证码 换一张
取 消