开发者

.NET Regex Equivalent of Python Regex's (?P=previousmatchname)

In Python's implementation of regular expressions you can do the following:

 <(?P<foo>.*)>(.*)</(?P=foo)>

and basically it will look for <this>right here</this> but not <this>right </here>. Basically it allows you to use the pre开发者_如何学Goviously captured named match later in your regex. Is there a way to do this with .NET's Regex?


You can use sharp brackets or single quotes and use \k to reference them:

<(?<foo>.*)>(.*)</(\k<foo>)>

or

<(?'foo'.*)>(.*)</(\k'foo')>

See this page for more info and scroll down to the "Named Capture with .NET’s System.Text.RegularExpressions" section.


try this:

<(?<foo>.*)>(.*)</\<foo>>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜