如何在 perl 正则表达式中匹配换行符 \n? [英] How to match a newline \n in a perl regex?

查看:265
本文介绍了如何在 perl 正则表达式中匹配换行符 \n?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配这条线,

<center>'''<font color="blue"><font size="18.0pt">No Change Alarms Help &amp; Information</font></font>'''</center>

并将其替换为,

=<center>'''<font color="blue">No Change Alarms Help &amp; Information</font>'''</center>=

现在,如果标签总是字体颜色或居中就很简单了,但它们绝对可以是任何东西,而且可以有多个.

Now it would be simple if the tags were always font colour or center, but they can be absolutely anything and there can be multiple of them.

我当前的代码是这样的:

My current code is this:

$html =~ s/<font size=".+">(.+)<\/font>/$1/g;

但这显然不会在每一端都做 =.

but this obviously does not do the = on each end.

我想做的是:

$html =~ s/\n(.+)<font size=".+">(.+)<\/font>(.+)\n/=$1$2$3=/g;

但是它无法匹配换行符,我不知道如何使它匹配它们,有什么线索吗?

However it fails to match the newline characters and I cannot figure out how to make it match them, any clues?

(我正在将 html 转换为 wiki 标记,但是转换器会填充字体大小,因此我手动将它们转换为 wiki 样式标题.)

(I'm converting html to wiki markup, however the converter stuffs up the font sizes so I'm manually converting them to wiki style headings.)

推荐答案

我所需要的只是查询末尾的 /gm,结果它默认忽略新行.

All I needed was /gm on the end of my query, turns out it ignores new lines by default.

这篇关于如何在 perl 正则表达式中匹配换行符 \n?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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