Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RegEx-基于链接文本删除HTML超链接_C#_Html_Regex - Fatal编程技术网

C# RegEx-基于链接文本删除HTML超链接

C# RegEx-基于链接文本删除HTML超链接,c#,html,regex,C#,Html,Regex,我有一些文本中有HTML超链接。 我想删除超链接,但只删除特定的超链接 e、 g.我从以下几点开始: This is text <a href="link/to/somewhere">Link to Remove</a> and more text with another link <a href="/link/to/somewhere/else">Keep this link</a> 这是一个文本,还有更多带有另一个链接的文本 我想要: T

我有一些文本中有HTML超链接。 我想删除超链接,但只删除特定的超链接

e、 g.我从以下几点开始:

This is text <a href="link/to/somewhere">Link to Remove</a> and more text with another link <a href="/link/to/somewhere/else">Keep this link</a>
这是一个文本,还有更多带有另一个链接的文本
我想要:

This is text and more text with another link <a href="/link/to/somewhere/else">Keep this link</a> 
这是一个文本,还有更多带有另一个链接的文本
我有这个正则表达式

<a\s[^>]*>.*?</a>
]*>.*?
。。。但它匹配所有链接

我需要向该表达式添加什么才能只匹配其中包含链接文本“Remove”(例如)的链接


提前谢谢

如果不在HTML上使用正则表达式,您可能会得到很多反馈。。。但如果您决定使用一个,请尝试以下方法:

 <a\s[^>]*>.*?Remove.*?</a>
]*>.*删除。*?

这就是“删除”在链接文本中的位置。

如果不在HTML上使用正则表达式,您可能会得到很多反馈。。。但如果您决定使用一个,请尝试以下方法:

 <a\s[^>]*>.*?Remove.*?</a>
$str=~/(.*)<a.*<\/a>([a-z ]+ <a.*<\/a>)/;
print "$1$2";
]*>.*删除。*?
这就是链接文本中“删除”的位置。

$str=~/(.*)
$str=~/(.*)(.*)(.*))

$str=~/(.*)<a.*<\/a>([a-z ]+ <a.*<\/a>)/;
print "$1$2";
重建为:$1$2


用$1$2重建

谢谢,明白了。如果我想将“删除”与不区分大小写匹配,我会用什么来包装它?(例如,匹配'Remove'或'Remove'或'Remove'等。)@Rob:非常确定C#有类似于
RegexOptions.IgnoreCase
的东西,可以作为另一个参数传入。谢谢,明白了。如果我想将“删除”与不区分大小写匹配,我会用什么来包装它?(例如,匹配'Remove'或'Remove'或'Remove'等。)@Rob:非常确定C#有类似于
RegexOptions.IgnoreCase的东西,可以作为另一个参数传入。