正则表达式以匹配带有+(加号)符号的单词 [英] Regex to match a word with + (plus) signs

查看:479
本文介绍了正则表达式以匹配带有+(加号)符号的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间,但仍然必须解决。我需要能够匹配字符串中带有符号(例如c ++)的单词的正则表达式。

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.

我用过 / \ bword\b / ,对于常用单词,可以正常运行。但是,一旦我尝试 / \bC\ + \ + \b / ,它就不起作用。

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.

我需要一个正则表达式来检测输入字符串中是否包含c ++单词。像这样的输入

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

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

等。

ps。使用C#.Net Regex.Match函数。

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

感谢帮助!

推荐答案

+ 是一个特殊字符,因此您需要对其进行转义

+ is a special character so you need to escape it

\bC\+\+(?!\w)

请注意,不能使用 \b ,因为 + 不是单词字符。

Note that we can't use \b because + is not a word-character.

这篇关于正则表达式以匹配带有+(加号)符号的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆