So I come up with this:
which I was quite proud of -- but instead of what I thought I'd get:$string = ' blah blah blah before-list text [ line one line 1 line one line 1 line 2 line two line 2 line two line line number 3 line three line number 3 line three line 4 ] blah blah later after-list text '; $string =~ s! ^\[$ # open-bracket as entire line (.*) # all including linebreaks - /s modifier ^\]$ # close-bracket as entire line !$x=$1; $x =~ s/^/<li>/g; # LIs at the start of each line "<ol>$x</ol>"; # return whole thing !smegx; # smeg -- how cool is that? print $string;
I got this:blah blah blah before-list text <ol> <li>line one line 1 line one line 1 <li>line 2 line two line 2 line two line <li>line number 3 line three line number 3 line three <li>line 4 </ol> blah blah later after-list text
and I can't quite figure out where that extra <li> has come from. The next '^' isn't right after the last '$'?blah blah blah before-list text <ol><li> <li>line one line 1 line one line 1 <li>line 2 line two line 2 line two line <li>line number 3 line three line number 3 line three <li>line 4 </ol> blah blah later after-list text
I'm sure my fellow monks can tell me where I'm going wrong.
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
M-J D
In reply to automagic-HTML regex by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |