我有一个包含一个HTML页面的响应一个字符串变量。它包含数百个标签,其中包括以下三个HTML标签:
I have a string variable that contains an HTML page's response. It contains hundreds of tags, including the the following three html tags:
<tag1 prefix1314030136543="2">
<tag2 prefix131403013654="1" anotherAttribute="432">
<tag3 prefix13140301376543="4">
我需要能够带出一个以preFIX开始伴随着它的价值,无论标记名的任何属性。最后,我想有:
I need to be able to strip out any attribute that starts with "prefix" along with its value, regardless of tag name. In the end, I'd like to have:
<tag1>
<tag2 anotherAttribute="432">
<tag3>
我使用C#。我假设正则表达式的解决方案,但我是可怕的与正则表达式,并希望有人能帮助我在这里。
I am using C#. I'm assuming RegEx is the solution, but I'm horrible with RegEx and hope someone can help me out here.
看的Html敏捷包。
使用正则表达式:
(?<=<[^<>]*)\sprefix\w+="[^"]"\s?(?=[^<>]*>)
var result = Regex.Replace(s,
@"(?<=<[^<>]*)\sprefix\w+=""[^""]""(?=[^<>]*>)", string.Empty);