c# - Regex setting word characters and matching exact word -
i need c# regex match full words, , need make sure +-/*() delimit words (i'm not sure if last part set way.) find regexes confusing , on matter. currently, regex is:
public regex codefunctions = new regex("draw_line|draw_rectangle|draw_circle");
thank you! :)
try
public regex codefunctions = new regex(@"\b(draw_line|draw_rectangle|draw_circle)\b");
the \b
means match word boundary, i.e. transition non-word character word character (or vice versa).
word characters include alphabet characters, digits, , underscore symbol. non-word characters include else, including +-/*()
, should work fine you.
see regex class documentation more details.
the @
@ start of string makes string verbatim string, otherwise have type 2 backslashes make 1 backslash.
Comments
Post a Comment