[英]Difference between the Regex expressions in dotnet
what is the difference between the two regex 两种正则表达式有什么区别
new Regex(@"(([[[{""]))", RegexOptions.Compiled)
and 和
new Regex(@"(^[[[{""])", RegexOptions.Compiled)
I've used the both regex but can't find the difference. 我已经使用了两个正则表达式,但找不到区别。 it's almost match similar things. 它几乎匹配类似的东西。
The regex patterns are not well written because 正则表达式模式写得不好,因为
The first regex - (([[[{""]))
- matches 1 character, either a [
, a {
, or a "
, and captures it into Group 1 and Group 2. See demo . It is equal to 第一个正则表达式- (([[[{""]))
-匹配1个字符,即[
,a {
或"
,并将其捕获到组1和组2中。请参见demo 。
[[{"]
The second regex - (^[[[{""])
- only matches the same characters as the pattern above, but at the beginning of a string (if RegexOptions.Multiline
is not set), or the beginning of a line (if that option is set). 第二个正则表达式- (^[[[{""])
-仅与上述模式匹配相同的字符,但匹配字符串的开头 (如果未设置RegexOptions.Multiline
) 或行的开头 (如果该选项已设置)。 See demo . 参见演示 。 It is equal to 等于
^[[{"]
You will access the matched characters using Regex.Match(s).Value
. 您将使用Regex.Match(s).Value
访问匹配的字符。
Aslo see Caret ^: Beginning of String (or Line) 请参阅插入符号^:字符串(或行)的开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.