Reputation: 543
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
I want to match Mountain. Nothing else. No other parts of that set. Just the exact line, Mountain. Everything I've tried either matches for all instances of Mountain or for none of them. Plenty of people want to match an exact word or phrase, but I seem to be the only one who wants to match only one exact word or phrase.
If this CAN be expanded to a phrase that would be perfect. Assume:
Go for a hike
Go for a hike, on a mountain.
I want to go for a hike.
Where I want to match only "Go for a hike" but no phrase that contains it.
Upvotes: 54
Views: 129545
Reputation: 324
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$
Upvotes: 3
Reputation: 375584
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.
Upvotes: 79