pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Perl pastebin - collaborative debugging tool View Help


Posted by Dan on Fri 27 Jun 22:12
report abuse | download | new post

  1. # Construct a regex fragment for handling normal tags. These can
  2. # be either a start or an end tag.
  3. my $standard_tags_fragment = join '|', qw{
  4.     h1  h2  h3  ul  ol  li
  5.     b   i   strong  em
  6.     s   sub super   strike
  7.     p   pre code    blockquote
  8. };;
  9.  
  10. # Define a regex to match standard, open or close tags
  11. my $standard_tags_re = qr{
  12.     <                               # Open tag
  13.         /?                          # Optional leading slash
  14.         (?:$standard_tags_fragment) # Regex fragment to match tagnames
  15.     >                               # Close tag
  16. }xms;
  17.  
  18. # Construct a regex fragment for handling single, self-closing tags
  19. my $single_tags_fragment = join '|', qw{ br hr };
  20.  
  21. my $single_tags_re = qr{
  22.     <                               # Open tag
  23.         (?:$single_tags_fragment)   # Regex fragment to match single tags
  24.         \s*/?                       # Optional self-closing slash, with optional space
  25.     >                               # Close tag
  26. };
  27.  
  28. # Construct the final whitespace regexp
  29. my $whitelist_re = qr{
  30.     $single_tags_re             # Match an open or close tag
  31.     |   $standard_tags_re       # Match a self-closing single tag
  32.  
  33.     # Special cases
  34.     |   <a[^>]+>                # Match 'a' tags regardless of attributes
  35.     |   <img[^>]+>              # Match 'img' regardless of attributes
  36.     |   </a>                    # Special case to catch close 'a' tags
  37. }xms;

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me