Regex: Matching against groups in different order without repeating the group

后端 未结 4 1288
遇见更好的自我
遇见更好的自我 2021-01-31 11:21

Let\'s say I have two strings like this:

XABY
XBAY

A simple regex that matches both would go like this:

X(AB|BA)Y
4条回答
  •  梦如初夏
    2021-01-31 11:44

    If there are several strings, with any kind of characters in there, you'll be better with:

    X(.)+Y
    

    Only numbers then

    X([0-9])+Y
    

    Only letters

    X([a-zA-Z])+Y
    

    Letters and numbers

    X([a-zA-Z][0-9])+Y
    

提交回复
热议问题