RegEx - reusing subexpressions

后端 未结 6 1537
傲寒
傲寒 2020-11-28 12:56

Say I have a regex matching a hexadecimal 32 bit number:

([0-9a-fA-F]{1,8})

When I construct a regex where I need to match this multiple ti

6条回答
  •  無奈伤痛
    2020-11-28 13:25

    Why not do something like this, not really shorter but a bit more maintainable.

    String.Format("(?{0})\s*:\s*(?{0})", "[0-9a-zA-Z]{1,8}");
    

    If you want more self documenting code i would assign the number regex string to a properly named const variable.

提交回复
热议问题