Regex to match exact phrase, nothing before or after the phrase

前端 未结 2 897
故里飘歌
故里飘歌 2020-12-13 13:38

I am not sure if this is exactly possible. Consider this example set of data:

Mountain
Big mountain
Mountain of stone
A mountain on a hill

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

    To match the exact line "Mountain" use this: /^Mountain$/

    You haven't mentioned what language you're working in, so the exact form of the pattern might have to change.

    0 讨论(0)
  • 2020-12-13 14:07

    If you have a string that contains multiple lines, the following two regular expressions may help:

    \r\nWORD\r\n|^WORD\r\n|\r\WORD$|^WORD$
    
    \r\nA\sPHRASE\r\n|^A\sPHRASE\r\n|\r\A\sPHRASE$|^A\sPHRASE$
    
    0 讨论(0)
提交回复
热议问题