正则表达式:匹配XYX,其中X和Y是任何字母

有没有一种方法可以通过松散指定的模式/组合来检索字符串?

数据:[AAA,ABA,CAC,CCA,BCB]

输入:XYX

输出:ABA,CAC,BCB

我正在使用nodeJS + mysql

评论
坏pi气
坏pi气

以下正则表达式可以完成这项工作:

/([A-Z])[A-Z]\1/g

It will look for an arbitrary capital letter, followed by another letter and a repetition of the first one. The g flag will make it applicable multiple times in a string.

点赞
评论