New 2011 FluxBB Parser

Documantation and Test Sandbox.

You are not logged in.

#1 2011-01-23 16:41:29

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Parser Regular Expressions

Code: Regex (PCREx) - "Smilies"

're_smilies' => '/ # re_smilies Rev:20110202_1500
# Match special smiley character sequences within BBCode content.
(?<=^|[>\s])                    # Only if preceeded by ">" or whitespace.
(?:\:\)|\=\)|\:\||\=\||\:\(|\=\(|\:D|\=D|\:o|\:O|;\)|\:\/|\:P|\:p|\:lol\:|\:mad\:|\:rolleyes\:|\:cool\:)
(?=$|[\[<\s])                   # Only if followed by "<", "[" or whitespace.
                                /Sx',


Code: Regex (PCREx) - "Color"

're_color' => '% # re_color Rev:20110202_1500
# Match a valid CSS color value. #123, #123456, or "red", "blue", etc.
^                               # Anchor to start of string.
(                               # $1: Foreground color (required).
  \#(?:[0-9A-Fa-f]{3}){1,2}     # Either a "#" and a 3 or 6 digit hex number,
| (?: maroon|red|orange|yellow| # or a recognized CSS color word.
      olive|purple|fuchsia|white|
      lime|green|navy|blue|aqua|
      teal|black|silver|gray
  )                             # End group of recognized color words.
)                               # End $1. Foreground color.
# Match optional CSS background color value. ;#123, ;#123456, or ;"red", "blue", etc.
(?:                             # Begin group for optional background color
  ;?+                           # foreground;background delimiter: e.g. "#123;#456".
  ((?1))                        # $2: Background color. (Same regex as the first.)
)?+                             # Background color spec is optional.
$                               # Anchor to end of string.
                                %ix'


Code: Regex (PCREx) - "Textile phrases"

're_textile' => '/ # re_textile Rev:20110202_1500
# Match textile inline phrase: _em_ *strong* @tt@ ^super^ ~sub~ -del- +ins+
([+\-@*_\^~])                   # $1: literal exposed start of phrase char, but
(?<=                            # only if preceded by...
  ^          [+\-@*_]           # start of string (for _em_ *strong* -del- +ins+ @code)
| \s         [+\-@*_]           # or whitespace   (for _em_ *strong* -del- +ins+ @code)
| [A-Za-z0-9)}\]>][\^~]         # or alphanum or bracket (for ^superscript^ ~subscript~).
)                               # only if preceded by whitespace or start of string.
(                               # $2: Textile phrase contents.
  [A-Za-z0-9({\[<]              # First char following delim must be alphanum or bracket.
  [^+\-@*_\^~\n]*+              # "normal*" == Zero or more non-delim, non-newline.
  (?>                           # Begin unrolling-the-loop. "(special normal*)*"
    (?!                         # One of two conditions must be true for inside delim:
      (?:(?<=[A-Za-z0-9)}\]>][.,;:!?])(?=\1(?:\s|$)))
    | (?:(?<=[A-Za-z0-9)}\]>])(?=\1(?:[\s.,;:!?]|$)))
    )[+\-@*_\^~]                # If so then not yet at phrase end. Match delim and
    [^+\-@*_\^~\n]*+            # more "normal*" non-delim, non-linefeeds.
  )*+                           # Continue unrolling. "(special normal*)*"
)                               # End $2: Textile phrase contents.
(?>
  (?:(?<=[A-Za-z0-9)}\]>][.,;:!?])(?=\1(?:\s|$)))
| (?:(?<=[A-Za-z0-9)}\]>])(?=\1(?:[\s.,;:!?]|$)))
)
\1                              # Match delim end of phrase, but only if
                                /Smx'


Code: Regex (PCREx) - "BBCode open and close tags and contents and attribute"

're_bbcode' => '% # re_bbcode Rev:20110202_1500
# First, match opening tag of syntax: "[TAGNAME (= ("\')ATTRIBUTE("\') )]";
\[                              # Match opening bracket of outermost opening TAGNAME tag.
(?>(b|code|color|colour|del|email|em|h|img|ins|i|list|\*|quote|sub|sup|s|tt|url|u|vimeo|youtube|err|dbug)\s*+) # $1:
(?>                             # Atomically group remainder of opening tag.
  (?:                           # Optional attribute.
    (=)\s*+                     # $2: = Optional attribute\'s equals sign delimiter, ws.
    (?:                         # Group for 1-line attribute value alternatives.
      \'([^\'\r\n\\\\]*+(?:\\\\.[^\'\r\n\\\\]*+)*+)\'  # Either $3: == single quoted,
    | "([^"\r\n\\\\]*+(?:\\\\.[^"\r\n\\\\]*+)*+)"      # or     $4: == double quoted,
    | ( [^[\]\r\n]*+            # or $5: == un-or-any-quoted. "normal*" == non-"[]"
        (?:                     # Begin "(special normal*)*" "Unrolling-the-loop" construct.
          \[[^[\]\r\n]*+\]      # Allow matching [square brackets] 1 level deep. "special".
            [^[\]\r\n]*+        # More "normal*" any non-"[]", non-newline characters.
        )*+                     # End "(special normal*)*" "Unrolling-the-loop" construct.
      )                         # End $5: Un-or-any-quoted attribute value.
    )                           # End group of attribute values alternatives.
    \s*+                        # Optional whitespace following quoted values.
  )?                            # End optional attribute group.
  \]                            # Match closing bracket of outermost opening TAGNAME tag.
)                               # End atomic group with opening tag remainder.
# Second, match the contents of the tag.
(                               # $6: Non-trimmed contents of TAGNAME tag.
  (?>                           # Atomic group for contents alternatives.
    [^\[]++                     # Option 1: Match non-tag chars (starting with non-"[").
    (?:                         # Begin "(special normal*)*" "Unrolling-the-loop" construct.
      (?!\[/?+\1[\]=\s])\[      # "special" = "[" if not start of [TAGNAME*] or [/TAGNAME].
      [^\[]*+                   # More "normal*".
    )*+                         # Zero or more "special normal*"s allowed for option 1.
  | (?:                         # or Option 2: Match non-tag chars (starting with "[").
      (?!\[/?+\1[\]=\s])\[      # "special" = "[" if not start of [TAGNAME*] or [/TAGNAME].
      [^\[]*+                   # More "normal*".
    )++                         # One or more "special normal*"s required for option 2.
  | (?R)                        # Or option 3: recursively match nested [TAGNAME]..[/TAGNAME].
  )*+                           # One of these three options as many times as necessary.
)                               # End $6: Non-trimmed contents of TAGNAME tag.
# Finally, match the closing tag.
\[/\1\s*+\]                     # Match outermost closing [/  TAGNAME  ]
                                %ix',


Code: Regex (PCREx) - "BBCode open or close tag"

're_bbtag' => '%# re_bbtag Rev:20110202_1500
# Match open or close BBtag.
\[/?+                           # Match opening bracket of outermost opening TAGNAME tag.
(?>(b|code|color|colour|del|email|em|h|img|ins|i|list|\*|quote|sub|sup|s|tt|url|u|vimeo|youtube|err|dbug)\s*+) #$1:
(?:                             # Optional attribute.
  (=)\s*+                       # $2: = Optional attribute\'s equals sign delimiter, ws.
  (?:                           # Group for 1-line attribute value alternatives.
    \'([^\'\r\n\\\\]*+(?:\\\\.[^\'\r\n\\\\]*+)*+)\'  # Either $3: == single quoted,
  | "([^"\r\n\\\\]*+(?:\\\\.[^"\r\n\\\\]*+)*+)"      # or     $4: == double quoted,
  | ( [^[\]\r\n]*+              # or $5: == un-or-any-quoted. "normal*" == non-"[]"
      (?:                       # Begin "(special normal*)*" "Unrolling-the-loop" construct.
        \[[^[\]\r\n]*+\]        # Allow matching [square brackets] 1 level deep. "special".
          [^[\]\r\n]*+          # More "normal*" any non-"[]", non-newline characters.
      )*+                       # End loop construct. See: "Mastering Regular Expressions".
    )                           # End $5: Un-or-any-quoted attribute value.
  )                             # End group of attribute values alternatives.
  \s*+                          # Optional whitespace following quoted values.
)?
\]                              # Match closing bracket of outermost opening TAGNAME tag.
                                %ix'

Offline

Board footer

Powered by FluxBB 1.4.5