Regex匹配另一场比赛 [英] Regex Matching another match

查看:53
本文介绍了Regex匹配另一场比赛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何匹配与另一场比赛匹配的任何内容?

例如,如果我有一个带文字的文本框:

class MyClass1

$

// ...

}

新MyClass1()

,它匹配类名((?< = class)。*),如何让它匹配MyClass1的所有实例?

解决方案

这个问题几乎包含了回答。获取 Match.Value ,这是一个字符串,并在另一个Regex的模式字符串中使用它。请参阅:

http:// msdn .microsoft.com / zh-cn / library / system.text.regularexpressions.capture.value.aspx [ ^ ]。



-SA

How would I match anything that matches another match?
For example, if I had a textbox with the text:
"class MyClass1
{
//...
}
new MyClass1()"
and it was matching class names ((?<=class ).*), how would I get it to match all instances of "MyClass1"?

解决方案

The question almost contains the answer. Get Match.Value, which is a string, and use it in another Regex's pattern string. Please see:
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.capture.value.aspx[^].

—SA


这篇关于Regex匹配另一场比赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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