删除字符串中的所有标签标签
我想从字符串中删除所有标签标签。
这是输入字符串。
<p>
<title>Contact Us</title>
</p>
<table dropzone="copy">
<tbody>
<tr>
<td class="label" style="cursor: default;">Full Name</td>
<td style=
"cursor: default;">[<label id="{0a4a7240-9606-416a-bf7b-ef11a47cca8e}">First name</label>] [<label id="{94263497-683b-46f9-ba0f-69f4c2736598}">Last name</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: d
efault;">Telephone</td>
<td style="cursor: default;">[<label id="{ce68e02e-e9fd-40ee-9375-ee1b05972e9b}">Phone</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Email</td>
<td style="cursor: default;">[<label id="{411b580e-f7e9-4dd2-a70d-947385360cd0}">Email</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Message</td>
<td style="cursor: default;">[
<label id="{13e2ff23-135c-4c6d-beb4-2960a533cb98}">Your Message</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Company</td>
<td style="cursor: default;">[<label id="{c3f22c3a-8fc1
-48a4-8d6a-fe346024ca2b}">Company</label>]</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
标签标签需要删除,但不应删除字符串内的值
&lt; label ID =“ {0a4a7240-9606-416a-416a-bf7b-ef11a47cca8e}”成为
名字
&lt; label ID =“ {CE68E02E-E9FD-40EE-9375-EE1B05972E9B}”代码>
label ID =“ {411B580E-F7E9-4DD2-A70D-947385360CD0}”
&lt ; id =“ {13E2FF23-135C-4C6D-BEB4-2960A533CB98}”&gt;您的消息&lt;/label&gt;
将成为您的消息>您的消息>
&lt; label ID = 8FC1-48A4-8D6A-FE346024CA2B}“&gt; company&lt;/label&gt;
将成为company
我尝试了以下Regex [Regex] label(。*)”
&lt ;
?s )
I want to remove all label tags from a string.
This is the input string.
<p>
<title>Contact Us</title>
</p>
<table dropzone="copy">
<tbody>
<tr>
<td class="label" style="cursor: default;">Full Name</td>
<td style=
"cursor: default;">[<label id="{0a4a7240-9606-416a-bf7b-ef11a47cca8e}">First name</label>] [<label id="{94263497-683b-46f9-ba0f-69f4c2736598}">Last name</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: d
efault;">Telephone</td>
<td style="cursor: default;">[<label id="{ce68e02e-e9fd-40ee-9375-ee1b05972e9b}">Phone</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Email</td>
<td style="cursor: default;">[<label id="{411b580e-f7e9-4dd2-a70d-947385360cd0}">Email</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Message</td>
<td style="cursor: default;">[
<label id="{13e2ff23-135c-4c6d-beb4-2960a533cb98}">Your Message</label>]</td>
</tr>
<tr>
<td class="label" style="cursor: default;">Company</td>
<td style="cursor: default;">[<label id="{c3f22c3a-8fc1
-48a4-8d6a-fe346024ca2b}">Company</label>]</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
The label tag needs to be removed but value inside the string should not be removed
<label id="{0a4a7240-9606-416a-bf7b-ef11a47cca8e}">First name</label>
will become First name
<label id="{ce68e02e-e9fd-40ee-9375-ee1b05972e9b}">Phone</label>
will become Phone
<label id="{411b580e-f7e9-4dd2-a70d-947385360cd0}">Email</label>
will become Email
<label id="{13e2ff23-135c-4c6d-beb4-2960a533cb98}">Your Message</label>
will become Your Message
<label id="{c3f22c3a-8fc1-48a4-8d6a-fe346024ca2b}">Company</label>
will become Company
I tried the following regex [Regex]::Match( $text, '(?s)<label(.*)">' ).Groups.Value but its not working.
Any suggestions would be appreciated
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这条正可能会起作用,您可以使用
-replace
操作员而不是呼叫regex.regex.replace
:请参阅
This regex could work, you can use the
-replace
operator instead of the call toRegex.Replace
:See https://regex101.com/r/3gbJEp/1 for details.
通常是试图用正则表达。
取而代之的是,使用专用的html解析器作为 htmldocument class
示例
It is generally a bad idea to attempt to parse HTML with regular expressions.
Instead use a dedicated HTML parser as the HtmlDocument class
Example