正则表达式来表达整个单词有特殊字符不工作匹配?

编程入门 行业动态 更新时间:2024-10-11 15:14:31
本文介绍了正则表达式来表达整个单词有特殊字符不工作匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我整个单词经历这个问题 Regex.Match

I was going through this question Regex.Match whole words

报告说,为全字匹配使用\bpattern\b 该工作正常全字匹配,没有任何特殊字符,因为它是为词只有字符!

It says for match whole word use "\bpattern\b" This works fine for match whole word without any special characters since it is meant for word characters only!

我需要一个表达式匹配特殊字符也的话。我的代码如下:

I need an expression to match words with special characters also. My code is as follows

class Program { static void Main(string[] args) { string str = Regex.Escape("Hi temp% dkfsfdf hi"); string pattern = Regex.Escape("temp%"); var matches = Regex.Matches(str, "\\b" + pattern + "\\b" , RegexOptions.IgnoreCase); int count = matches.Count; } }

但它失败的原因为%。难道我们有什么办法解决这个? 也有其他特殊字符,如'空间','(',')'等

But it fails because of %. Do we have any workaround for this? There can be other special characters like 'space','(',')', etc

推荐答案

在这个问题的答案可以在这里找到。

The answer to this Question can be found here

的正则表达式表达全字匹配

谢谢!

更多推荐

正则表达式来表达整个单词有特殊字符不工作匹配?

本文发布于:2023-11-02 12:10:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   特殊字符   工作   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!