正则表达式替换记事本++中的html空格和前导空格 [英] Regex to replace html whitespace and leading whitespace in notepad++

查看:10
本文介绍了正则表达式替换记事本++中的html空格和前导空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试使用以下正则表达式删除html空格和前导空格

Find:   s*([<>])s*

Replace: $1

但每次我这样做时,我的文档中都会出现186个1美元字面上的值。如有任何帮助,我们将不胜感激

这里是我所说的一个例子

<fieldset id="prod_desc">
<p>Original AA </p>
<b>Features:</b> 
<ul>
  <li>2 pole rectangular dome tent with 13.4 sq ft of vestibule storage </li>
  <li>Durable, shockcorded, self-supporting fiberglass frame and ring and pin/pole pocket assembly </li>
  <li>2 side opening door panels are constructed entirely of no see-um mesh to maximize air flow inside </li>
  <li>Poke-out vent in side wall allows the option of additional ventilation when needed </li>
  <li>2 interior storage pockets keep essential items handy Specifications: </li>
  <li>Season: 3 </li>
  <li>Sleeps: 2 </li>
  <li>Doors: 2 </li>
  <li>Windows: 2 </li>
  <li>Weight: 5 lbs 12 oz </li>
  <li>Area: 36.5 Sq. Ft. </li>
  <li>Center Height: 3' 7.5&quot;</li>
</ul>
</fieldset> 

应变为:

<fieldset id="prod_desc"><p>Original AA</p><b>Features:</b><ul><li>2 pole rectangular dome tent with 13.4 sq ft of vestibule storage</li><li>Durable, shockcorded, self-supporting fiberglass frame and ring and pin/pole pocket assembly</li><li>2 side opening door panels are constructed entirely of no see-um mesh to maximize air flow inside</li><li>Poke-out vent in side wall allows the option of additional ventilation when needed</li><li>2 interior storage pockets keep essential items handy Specifications:</li><li>Season: 3</li><li>Sleeps: 2</li><li>Doors: 2</li><li>Windows: 2</li><li>Weight: 5 lbs 12 oz</li><li>Area: 36.5 Sq. Ft.</li><li>Center Height: 3' 7.5&quot;</li></ul></fieldset>

推荐答案

Notepad++在引入查找和替换的PCRE支持时,不支持$1版本6.0之前的反向引用。对于旧版本,请使用1进行反向引用。

您应该找到s*(<[^>]+>)s*。从2012年3月发布的Notepad++6.0版开始,仅此一项就应该适用于您。我试过您原来的正则表达式,它同样有效,这让我非常惊讶。

以前的版本不能进行多行正则表达式替换。要剥离换行符,请先执行正则表达式替换,然后执行扩展查找(UNIX行尾):



对于Windows行结尾:



将任一大小写替换为空。

这篇关于正则表达式替换记事本++中的html空格和前导空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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