[英]Regex - Match word against sentence
I'd like to write a regex query to be run on a set of elements. 我想编写一个正则表达式查询,以在一组元素上运行。
The query should return an element, as long as the search term matches the start of the word, and that all the words in the search term are in the match string. 只要搜索词匹配单词的开头,并且搜索词中的所有单词都在匹配字符串中,则查询应返回一个元素。
For example: 例如:
Search Term: "hell"
matches: "hello", "oh hello", "oh-hello"
doesn't match: "shell" - doesn't start the word out
My first attempt was to use BEGINSWITH[c]
, however that wouldn't match "oh hello" from above. 我的第一次尝试是使用
BEGINSWITH[c]
,但是从上面不能匹配“ oh hello”。 So I think I probably need to use MATCHES[c] %@
and use some sort of regex. 因此,我想我可能需要使用
MATCHES[c] %@
并使用某种正则表达式。 Anybody good with regex to have some ideas? 使用正则表达式的人有什么想法吗?
正则表达式
^hell[^ ]+|[^ ]+[ -]hell[^ ]+
I have used the below find anywhere that matches a word; 我在任何与单词匹配的地方使用了下面的查找;
\bHell(o|)?\b
i don't believe that is the best way as the ...(o|)? 我不认为这是...(o |)的最佳方法? is telling Regex to find where it matches Hell and then anywhere that 'Hell' has an o after it.
告诉正则表达式查找与地狱匹配的位置,然后在“地狱”之后带有o的任何位置。
Hope that helps 希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.