c# - Regex for containing a word with specific characters -


i need regex find whether sentence contain word. if word having prefix or postfix word in valid valid specific characters ,.*+- etc below example. searching process word, valid sentence make them bold

  1. processes
  2. process
  3. processing
  4. process-specific
  5. processed
  6. processor
  7. procession
  8. inter-process
  9. uniprocessor
  10. multiprocessing
  11. process's
  12. "process"
  13. process10

use word-boundary class (\b):

\bprocess\b 

in case-insensitive regex match should give correct result:

string[] strings = new string[] {     @"processes",     @"process",     @"processing",     @"process-specific",     @"processed",     @"processor",     @"procession",     @"inter-process",     @"uniprocessor",     @"multiprocessing",     @"process's",     @"""process""",     @"process10" };  foreach (string s in strings) {     if (regex.ismatch(s, @"\bprocess\b", regexoptions.ignorecase))         console.foregroundcolor = consolecolor.green;     else         console.foregroundcolor = consolecolor.red;     console.writeline(s); } 

enter image description here

if trailing numbers allowed, do:

\bprocess(?:\b|\d+) 

enter image description here


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -