Alex Rivera | Logout

Regex to match a word with + (plus) signs

Asked 2010-09-04T11:06:59.130
15

I've spent some time, but still have to solution. I need regular expression that is able to match a words with signs in it (like c++) in string.

I've used /\bword\b/, for "usual" words, it works OK. But as soon as I try /\bC\+\+\b/ it just does not work. It some how works wrong with a plus signs in it.

I need a regex to detect if input string contains c++ word in it. Input like,

"c++ developer"
"using c++ language" 

etc.

ps. Using C#, .Net Regex.Match function.

Thanks for help!

Edit
Report

1 Answer

0

As the others said, your problem isn't the + sign you've escaped correctly but the \b that is a zero-lenght char that match word boundary that takes place between word \w and non-word \W char.

There is also another mistake in your regex, you want to match char C (uppercase) with c++ (lowercase).To do so you have to change your regex to /\bc\+\+/ or use the i modifier to match case insensitive : /\bc\+\+/i

answered 2010-09-04T11:33:58.913

Your Answer