To convert the markdown italic text $script into html, I've written this:
my $script = "*so what*";
my $res =~ s/\*(.)\*/$1/g;
print "<em>$1</em>\n";
The expected result is:
<em>so what</em>
but it gives:
<em></em>
How to make it give the expected result?
Problems:
.won't match more than one character.Fix:
or
But that's not it. Even with all the aforementioned problems fixed, your parser still has numerous other bugs. For example, it misapplies italics for all of the following:
**Important**Correct: Important
Your code: *Important*
4 * 5 * 6 = 120Correct: 4 * 5 * 6 = 120
Your code: 4 5 6 = 120
4 * 6 = 20 is *wrong*Correct: 4 * 6 = 20 is wrong
Your code: 4 6 = 20 is wrong*
`foo *bar* baz`Correct:
foo *bar* bazYour code: `foo bar baz`
\*I like stars\*Correct: *I like stars*
Your code: \I like stars\