C#正则表达式转义序列 [英] C# Regex Escape Sequences

查看:143
本文介绍了C#正则表达式转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有的完整的正则表达式的地方转义序列的列表?我发现,但它缺少 \ \ \e 对于初学者。到目前为止,我已经提出了有希望所有的转义序列匹配这个正则表达式:

  @\\([ bBdDfnreasStvwWnAZG\\] | X [A-Z0-9] {2} | U [A-Z0-9] {4} | \d {1,3} | K< \w +>) 


解决方案

另外,如果你只是想逃避字符串正确,你可以只依靠 Regex.Escape( ) 将做必要的转义为你



提示:还有一个的 Regex.Unescape()


Is there a complete list of regex escape sequences somewhere? I found this, but it was missing \\ and \e for starters. Thus far I have come up with this regex pattern that hopefully matches all the escape sequences:

 @"\\([bBdDfnreasStvwWnAZG\\]|x[A-Z0-9]{2}|u[A-Z0-9]{4}|\d{1,3}|k<\w+>)"

解决方案

Alternatively, if you only want to escape a string correctly, you could just depend on Regex.Escape() which will do the necessary escaping for you.

Hint: There is also a Regex.Unescape()

这篇关于C#正则表达式转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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