如何从每个页面上的表单元素带出一个共同的属性? [英] How to strip out one common attribute from every form element on the page?

查看:88
本文介绍了如何从每个页面上的表单元素带出一个共同的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个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);

这篇关于如何从每个页面上的表单元素带出一个共同的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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