正则表达式匹配偶数个字母 [英] Regex match even number of letters
本文介绍了正则表达式匹配偶数个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将 Python 中的表达式与仅匹配偶数个字母出现的正则表达式进行匹配.例如:
<前>AAA # 不匹配AA#匹配fsfaAAasdf # 匹配sAfA # 匹配sdAAewAsA # 匹配AeAiA # 不匹配偶数个 As SHOULD 匹配.
解决方案
试试这个正则表达式:
^[^A]*((AA)+[^A]*)*$
如果 A
不需要连续:
^[^A]*(A[^A]*A[^A]*)*$
I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:
AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match
An even number of As SHOULD match.
解决方案
Try this regular expression:
^[^A]*((AA)+[^A]*)*$
And if the A
s don’t need to be consecutive:
^[^A]*(A[^A]*A[^A]*)*$
这篇关于正则表达式匹配偶数个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文