简体   繁体   中英

Regex: Identify words that contain 'ing'

I'm dealing with a sentence where I need to find the 'verb' of the sentence; that is to identify the words ending with 'ing'. How do I use regex to do this folks?

He is watching a movie

VERB: watch ing

好像您想要这样的东西,

@"\b\w+?ing\b"
Regex.Match(@"(?i)\w+ing(\W|$)")

应该做到这一点,我假设您也要识别waTchIng之类的单词,(?i)将指示正则表达式引擎忽略大小写。

You can do it without Regex:

string sentence="He is watching a movie";
var verbs= sentence.Split(' ').Where(x=> x.EndsWith("ing"));

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