OR condition in Regex

后端 未结 3 1979
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 10:40

Let\'s say I have

1 ABC Street
1 A ABC Street

With \\d, it matches 1 (what I expect), with \\d

3条回答
  •  借酒劲吻你
    2020-12-24 11:30

    Try

    \d \w |\d
    

    or add a positive lookahead if you don't want to include the trailing space in the match

    \d \w(?= )|\d
    

    When you have two alternatives where one is an extension of the other, put the longer one first, otherwise it will have no opportunity to be matched.

提交回复
热议问题