【问题标题】:Remove unnecessary strings and special characters using powershell使用 powershell 删除不必要的字符串和特殊字符
【发布时间】:2020-11-11 13:41:38
【问题描述】:

我有这个字符串:

$html = @'
<div><span style="display:inline !important;">As an Inventory and OperationsAgent</span></div><div><span style="display:inline !important;">I want to be able to raise internal EPL Nominations for Buildings that are going through a Shared Installation journey</span></div><div><span style="display:inline !important;">So that internal EPLNominations can be submitted when the TDF cost is too expensive for both P2P and Shared</span></div>
'@

...如何删除所有 HTML 标签?

【问题讨论】:

  • 我需要
    作为 Inventory and OperationsAgent
    我希望能够为正在经历共享安装过程的建筑物提高内部 EPL 提名
    所以当 P2P 和共享的 TDF 成本太高时,可以提交内部 EPLNominations
    "
  • 我需要删除
    这些类型的字符串和特殊字符。
  • 我只需要这样:作为一名库存和运营代理,我希望能够为正在经历共享安装过程的建筑物提高内部 EPL 提名。
  • 你能帮我尽快解决这个问题吗?
  • 我已重新格式化您的问题,请检查它确实是您想问的。如果没有,请edit your existing post 而不是使用 cmets :)

标签: powershell powershell-4.0


【解决方案1】:

您可以使用-replace 正则表达式运算符来删除所有html标签:

$html -replace '<[^>]+>'

也将, 替换为&lt;div&gt; 边界:

$html -replace '</div>\s*<div>',', ' -replace '<[^>]+>'

这将输出如下字符串:

作为一名库存和运营代理,我希望能够为正在经历共享安装过程的建筑物提高内部 EPL 提名,以便当 P2P 和共享的 TDF 成本太高时可以提交内部 EPL 提名

【讨论】:

  • 使用你的命令我无法完全删除。 <DIV><DIV><P>登录 CRM< /P></DIV></DIV><DIV><P>用户应该能够登录到 CRM</P></DIV>
  • <DIV><DIV><P>登录到 CRM</P></DIV></DIV><DIV><P>用户应该能够登录 CRM</P></DIV><DIV><DIV><P>转到订购产品并打开任何现有记录</P></DIV></DIV>< DIV><P>用户应该能够打开现有记录</P></DIV><DIV><P>将“准备付款”设置为是,并将收到发票或发票请求标志设置为是在订单产品表单上</P></DIV><P>不应显示错误消息,用户应该能够
  • 我还需要删除这些东西<DIV><DIV><P>你能帮帮我吗
  • @MohammadHafiz 然后更新您的问题,它没有说明双重编码的 HTML
  • 需要单独提问?
【解决方案2】:

你可以先解码你的html,然后替换html标签:

$DecodedHtml = [System.Web.HttpUtility]::htmldecode($html)
$DecodedHtml -replace '<[^>]*>'

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签