Regex match even number of letters

后端 未结 8 1093
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 05:35

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                


        
8条回答
  •  旧巷少年郎
    2020-12-06 06:08

    Try this regular expression:

    ^[^A]*((AA)+[^A]*)*$
    

    And if the As don’t need to be consecutive:

    ^[^A]*(A[^A]*A[^A]*)*$
    

提交回复
热议问题