OR condition in Regex

后端 未结 3 1984
爱一瞬间的悲伤
爱一瞬间的悲伤 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:29

    I think what you need might be simply:

    \d( \w)?
    

    Note that your regex would have worked too if it was written as \d \w|\d instead of \d|\d \w.

    This is because in your case, once the regex matches the first option, \d, it ceases to search for a new match, so to speak.

提交回复
热议问题