我陷入了一个简单的问题。
我正在使用 RegEx 从 html 标记中提取 url。我想添加常量前缀
"The site is"
到提取的正则表达式组。
示例标记:
<html>
<body>
<a href="www.stackoverflow.com"></a>
</body>
</html>
我使用的表达式是:
<a\shref="(?<Url>.*?)"></a>
当前我得到的组网址为
www.stackoverflow.com
但我想要这样
The site is www.stackoverflow.com
我怎样才能得到它?
最佳答案
Regex regex = new Regex(@"<a\shref=""(?<Url>.*?)""></a>")
String input = ... // your sample markup
String result = regex.Match(input).Result("The site is ${Url}");
关于c# - 将常量字符串添加到正则表达式组的前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12086487/