in reply to Editting Part of Regex
substr($string, index($string, '<tag>'), rindex($string, '</tag>')) =~ + s/\n(?!$)/<br>/g;
Yech! It gets rid of the negative look-ahead assertion (since the length is corrected), but it's ugly, and duplicates some function calls. A better version (but uses temp vars) is:substr($string, index($string, '<tag>'), rindex($string, '</tag>') - i +ndex($string, '<tag>')) =~ s/\n/<br>/g;
Much better. Though I'm still not sure if it's an improvement over the other suggestions above.my $st = index($string, '<tag>'); my $en = rindex($string, '</tag>') - $st; substr($string, $st, $en) =~ s/\n/<br>/g;
|
|---|