regex - C# Regular expression pattern what this matches for -
can sombody explain regex check for
regex x = new regex("{([^}]+)}");
it looks {...}
(1 or more) non-}
inside. if successful puts content of {...}
in capture group 1.
regex x = new regex("{([^}]+)}"); var m = x.match("{hello}"); string str0 = m.groups[0].tostring(); // {hello} string str1 = m.groups[1].tostring(); // hello
group 0 whole match.
var m2 = x.match("{}"); var success = m2.success; // false
it isn't anchored, have more 1 match each string...
var m2 = x.matches("{hello}{}{world}"); int c = m2.count; // 2 matches. {} wasn't match, {hello} , {world}
as sidenote, if think beginning c# parser, on wrong road :-) expressions { { string str = "hello"; } str += "x"; }
confuse regex, expressions { string str = "}" }
. stackless regex. no fancy tricks.
Comments
Post a Comment