正则表达式中问号等特殊字符的转义

在.NET Framework 开发人员指南 的 字符转义 一节 有这样一段话。
除 .$ ^ { [ ( | ) * + ? / 外,其他字符与自身匹配。
但是其中并未注明这些字符应该匹配为什么字符。
为了方便自己以后查阅,也为了方便网友搜索我就写在这里了。

[Sipo]
点的转义:.  ==> //u002E
美元符号的转义:$  ==> //u0024
乘方符号的转义:^  ==> //u005E
左大括号的转义:{  ==> //u007B
左方括号的转义:[  ==> //u005B
左圆括号的转义:(  ==> //u0028
竖线的转义:| ==> //u007C
右圆括号的转义:) ==> //u0029
星号的转义:*  ==> //u002A
加号的转义:+  ==> //u002B
问号的转义:?  ==> //u003F
反斜杠的转义:/ ==> //u005C

 

按组名分组引用



The following code example uses named grouping constructs to capture substrings from a string containing data in a "DATANAME:VALUE" format that the regular expression splits at the colon (:).

    Regex r = new Regex("^(?<name>//w+):(?<value>//w+)");
    Match m = r.Match("Section1:119900");


This regular expression returns the following output

m.Groups["name"].Value = "Section1"
m.Groups["value"].Value = "119900"

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值