Regex to match a word with + (plus) signs

后端 未结 5 1485
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 01:46

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 /\

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 02:11

    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

提交回复
热议问题