本文介绍了正则表达式匹配确切的短语,短语前后没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我不确定这是否完全可能.考虑这个示例数据集:

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

我想匹配山.没有其他的.没有其他部分.正是这条线,山.我尝试过的所有东西要么匹配 Mountain 的所有实例,要么不匹配.很多人都想匹配一个精确的单词或短语,但我似乎是唯一一个只想匹配一个精确的单词或短语的人.

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.

推荐答案

要匹配精确的Mountain"行,请使用:/^Mountain$/

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.

这篇关于正则表达式匹配确切的短语,短语前后没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 00:56