简体   繁体   中英

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. So I think I probably need to use MATCHES[c] %@ and use some sort of regex. 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|)? is telling Regex to find where it matches Hell and then anywhere that 'Hell' has an o after it.

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM