Reuse part of a Regex pattern

前端 未结 6 1555
北海茫月
北海茫月 2020-11-28 14:40

Consider this (very simplified) example string:

1aw2,5cx7

As you can see, it is two digit/letter/letter/digit values separated

6条回答
  •  醉话见心
    2020-11-28 14:40

    Try using back referencing, i believe it works something like below to match

    1aw2,5cx7
    

    You could use

    (\d\w\w\d),\1
    

    See here for reference http://www.regular-expressions.info/backref.html

提交回复
热议问题