I look at MarkDown code written by John Gruber in Perl, and there is a _Detab subchannel that converts tabs to spaces, preserving text indents. The line of code in question is 1314 in Markdown.pl:
$text =~ s{(.*?)\t}{$1.(' ' x ($g_tab_width - length($1) % $g_tab_width))}ge;
Wouldn't that lead to an unnecessary retreat? Would the following pattern be more efficient?
/([^\t\n]*)\t/
Or am I missing something? Thanks.
By the way, I only deny \n , not \r , because all line breaks are standardized to \n in advance.
performance regex perl markdown
jordanbtucker
source share