in reply to Re: good syntax highlighter for regexp?
in thread good syntax highlighter for regexp?
As mentioned, the main problem is that while this handles basic (a|b|c) groupings, it doesn't do nested groupings like (aaaa(b|c)) or ((?=pretext)aaaa). And because it's using regex to parse regex, there are other things that it doesn't do right when there are many special metacharacters in a row like a{1,3}.*?[def]+.my $HighlightText = $CgiArgsRef->{'RawValue'}; $HighlightText =~ s/&/&/go; $HighlightText =~ s/ / /go; # also use nor +mal spaces so line wrap is still possible $HighlightText =~ s/\t/ /go; # also use nor +mal spaces so line wrap is still possible $HighlightText =~ s/</</go; $HighlightText =~ s/>/>/go; $HighlightText =~ s/\r\n/<br>/go; # escaped characters $HighlightText =~ s/(\\\S)/<span class="escapedregexhighlight" +>$1<\/span>/gso; my $n = 1; # groupings like (..) $HighlightText =~ s/([^\\]?|^)(\()(.+?[^\\])(\))/sprintf("%s<s +pan class=\"searchregexhighlight\">%s<\/span><span class=\"groupregex +textcolor\">%s<\/span><span class=\"searchregexhighlight\">%s<\/span> +<span class=\"parametersup\">\0x00%s<\/b><\/span>",$1,$2,$3,$4,$n++)/ +gsoe; # single chars like . * ^ $ ? + and aggregates like {} and [] $HighlightText =~ s/([^\\]|^)([\.\+\*\?]+|[\^\$\(]|\)\+?\??\*? +\{?\d*,?\d*\}?|\[.+?\]\+?\??\*?\{?\d*,?\d*\}?|\{\d*,?\d*\})/$1<span c +lass="searchregexhighlight">$2<\/span>/gso; # other characters $HighlightText =~ s/\\{0}(\\[\w\s\d])/<span class="searchregex +highlight">$1<\/span>$3/gso; # put back the '$' in parameter subscripts $HighlightText =~ s/\0x00/\$/go; $HighlightText =~ s/[\r\n]+/<br>\n/go;
|
|---|