Regex match exact number not if it exist in string

前端 未结 2 1392
有刺的猬
有刺的猬 2020-12-12 06:28

My regex:

/3\\b/

Matches:

103

134,256,3

I want it to only match the lone 3. The number 3 will be a dyna

相关标签:
2条回答
  • 2020-12-12 06:53

    If you want to match only 3 in line you can use anchors like this:

    ^3$
    

    On the other hand if you want to match 3 in a line with more data you need to add an additional \b at your regex as Barmar showed in her answer

    0 讨论(0)
  • 2020-12-12 06:54

    Put a word boundary before it as well:

    \b3\b
    
    0 讨论(0)
提交回复
热议问题