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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -