I want to match this line,
<center>'''<font color="blue"><font size="18.0pt">No Change Alarms Help & Information</font></font>'''</center>
and replace it with,
=<center>'''<font color="blue">No Change Alarms Help & 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.
What I would like to do is this:
$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?
(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.)
i think this will work,using the /s modifier, which mnemonically means to "treat string as a single line". This changes the behaviour of "." to match newline characters as well. In order to match the beginning of this comment to the end, we add the /s modifier like this: $str =~ s/<!
"\n" matches a newline character.
By default in most regex engines, . doesn't match newline characters, so the matching stops at the end of each logical line. If you want . to match really everything, including newlines, you need to enable "dot-matches-all" mode in your regex engine of choice (for example, add re. DOTALL flag in Python, or /s in PCRE.
According to regex101.com \s : Matches any space, tab or newline character.
All I needed was /gm
on the end of my query, turns out it ignores new lines by default.
In some cases it might not work because of how perl "slurps" the input. Passing -0777
as a parameter will make it consider multiple lines. (Pass it along with your other parameters, e.g. perl -0777pi -e
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With