Copied!

Provides regular expressions and utilities for parsing Markdown

All of the PARTIAL_ regex constants assume that they'll be used in case-insensitive searches All other complete regexes provided by this class (either via constants or methods) will have case-insensitivity enabled.

  • phpcs:disable Generic.Strings.UnnecessaryStringConcat.Found
  • psalm-immutable
CloneableFinalInstantiable
Constants
public League\CommonMark\Util\RegexHelper::PARTIAL_ATTRIBUTE = '(?:\s+[a-z_:][a-z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))?)'
public League\CommonMark\Util\RegexHelper::PARTIAL_ATTRIBUTENAME = '[a-z_:][a-z0-9:._-]*'
public League\CommonMark\Util\RegexHelper::PARTIAL_ATTRIBUTEVALUE = '(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*")'
public League\CommonMark\Util\RegexHelper::PARTIAL_ATTRIBUTEVALUESPEC = '(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))'
public League\CommonMark\Util\RegexHelper::PARTIAL_BLOCKTAGNAME = '(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)'
public League\CommonMark\Util\RegexHelper::PARTIAL_CDATA = '<!\[CDATA\[[\s\S]*?]\]>'
public League\CommonMark\Util\RegexHelper::PARTIAL_CLOSEBLOCKTAG = '<\/(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)\s*[>]'
public League\CommonMark\Util\RegexHelper::PARTIAL_CLOSETAG = '<\/[a-z][a-z0-9-]*\s*[>]'
public League\CommonMark\Util\RegexHelper::PARTIAL_DECLARATION = '<![A-Za-z]+[^>]*>'
public League\CommonMark\Util\RegexHelper::PARTIAL_DOUBLEQUOTEDVALUE = '"[^"]*"'
public League\CommonMark\Util\RegexHelper::PARTIAL_ENTITY = '&(?:#x[a-f0-9]{1,6}|#[0-9]{1,7}|[a-z][a-z0-9]{1,31});'
public League\CommonMark\Util\RegexHelper::PARTIAL_ESCAPABLE = '[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]'
public League\CommonMark\Util\RegexHelper::PARTIAL_ESCAPED_CHAR = '\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]'
public League\CommonMark\Util\RegexHelper::PARTIAL_HTMLBLOCKOPEN = '<(?:(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[\s\/>]|$)|\/(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[\s>]|$)|[?!])'
public League\CommonMark\Util\RegexHelper::PARTIAL_HTMLCOMMENT = '<!-->|<!--->|<!--[\s\S]*?-->'
public League\CommonMark\Util\RegexHelper::PARTIAL_HTMLTAG = '(?:<[a-z][a-z0-9-]*(?:\s+[a-z_:][a-z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))?)*\s*\/?>|<\/[a-z][a-z0-9-]*\s*[>]|<!-->|<!--->|<!--[\s\S]*?-->|[<][?][\s\S]*?[?][>]|<![A-Za-z]+[^>]*>|<!\[CDATA\[[\s\S]*?]\]>)'
public League\CommonMark\Util\RegexHelper::PARTIAL_IN_DOUBLE_QUOTES = '"(\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^"\x00])*"'
public League\CommonMark\Util\RegexHelper::PARTIAL_IN_PARENS = '\((\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^)\x00])*\)'
public League\CommonMark\Util\RegexHelper::PARTIAL_IN_PARENS_NOSP = '\(([^\\()\x00-\x20]|\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|\\)*\)'
public League\CommonMark\Util\RegexHelper::PARTIAL_IN_SINGLE_QUOTES = ''(\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^'\x00])*''
public League\CommonMark\Util\RegexHelper::PARTIAL_LINK_TITLE = '^(?:"(\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^"\x00])*+"|'(\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^'\x00])*+'|\((\\[!"#$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~-]|[^()\x00])*+\))'
public League\CommonMark\Util\RegexHelper::PARTIAL_OPENBLOCKTAG = '<(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s+[a-z_:][a-z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))?)*\s*\/?>'
public League\CommonMark\Util\RegexHelper::PARTIAL_OPENTAG = '<[a-z][a-z0-9-]*(?:\s+[a-z_:][a-z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))?)*\s*\/?>'
public League\CommonMark\Util\RegexHelper::PARTIAL_PROCESSINGINSTRUCTION = '[<][?][\s\S]*?[?][>]'
public League\CommonMark\Util\RegexHelper::PARTIAL_REG_CHAR = '[^\\()\x00-\x20]'
public League\CommonMark\Util\RegexHelper::PARTIAL_SINGLEQUOTEDVALUE = ''[^']*''
public League\CommonMark\Util\RegexHelper::PARTIAL_TAGNAME = '[a-z][a-z0-9-]*'
public League\CommonMark\Util\RegexHelper::PARTIAL_UNQUOTEDVALUE = '[^"'=<>`\x00-\x20]+'
public League\CommonMark\Util\RegexHelper::REGEX_LINK_DESTINATION_BRACES = '/^(?:<(?:[^<>\n\\\x00]|\\.)*>)/'
public League\CommonMark\Util\RegexHelper::REGEX_NON_SPACE = '/[^ \t\f\v\r\n]/'
public League\CommonMark\Util\RegexHelper::REGEX_PUNCTUATION = '/^[!"#$%&'()*+,\-.\/:;<=>?@\[\]\\^_`{|}~\p{P}\p{S}]/u'
public League\CommonMark\Util\RegexHelper::REGEX_SAFE_DATA_PROTOCOL = '/^data:image\/(?:png|gif|jpeg|webp)/i'
public League\CommonMark\Util\RegexHelper::REGEX_THEMATIC_BREAK = '/^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/'
public League\CommonMark\Util\RegexHelper::REGEX_UNICODE_WHITESPACE_CHAR = '/^\pZ|\s/u'
public League\CommonMark\Util\RegexHelper::REGEX_UNSAFE_PROTOCOL = '/^javascript:|vbscript:|file:|data:/i'
public League\CommonMark\Util\RegexHelper::REGEX_WHITESPACE_CHAR = '/^[ \t\n\x0b\x0c\x0d]/'
Methods
public static getHtmlBlockCloseRegex(int $type) : string
 
  • internal
  • param int $type HTML block type
  • psalm-param HtmlBlock::TYPE_* $type
  • phpstan-param HtmlBlock::TYPE_* $type
  • psalm-return non-empty-string
  • throws \InvalidArgumentException if an invalid type is given
  • psalm-pure
public static getHtmlBlockOpenRegex(int $type) : string
 
  • internal
  • param int $type HTML block type
  • psalm-param HtmlBlock::TYPE_* $type
  • phpstan-param HtmlBlock::TYPE_* $type
  • psalm-return non-empty-string
  • throws \InvalidArgumentException if an invalid type is given
  • psalm-pure
public static isEscapable(string $character) : bool
 
  • psalm-pure
public static isLetter(?string $character) : bool
 
  • psalm-pure
public static isLinkPotentiallyUnsafe(string $url) : bool
 
  • psalm-pure
public static isWhitespace(string $character) : bool
public static matchAt(string $regex, string $string, int $offset = 0) : ?int
 

Attempt to match a regex in string s at offset offset

  • psalm-param non-empty-string $regex
  • return int|null Index of match, or null
  • psalm-pure
public static matchFirst(string $pattern, string $subject, int $offset = 0) : ?array
 

Functional wrapper around preg_match_all which only returns the first set of matches

  • psalm-param non-empty-string $pattern
  • return string[]|null
  • psalm-pure
public static unescape(string $string) : string
 

Replace backslash escapes with literal characters

  • psalm-pure
Methods
public static getHtmlBlockCloseRegex(int $type) : string
 
  • internal
  • param int $type HTML block type
  • psalm-param HtmlBlock::TYPE_* $type
  • phpstan-param HtmlBlock::TYPE_* $type
  • psalm-return non-empty-string
  • throws \InvalidArgumentException if an invalid type is given
  • psalm-pure
public static getHtmlBlockOpenRegex(int $type) : string
 
  • internal
  • param int $type HTML block type
  • psalm-param HtmlBlock::TYPE_* $type
  • phpstan-param HtmlBlock::TYPE_* $type
  • psalm-return non-empty-string
  • throws \InvalidArgumentException if an invalid type is given
  • psalm-pure
public static isEscapable(string $character) : bool
 
  • psalm-pure
public static isLetter(?string $character) : bool
 
  • psalm-pure
public static isLinkPotentiallyUnsafe(string $url) : bool
 
  • psalm-pure
public static isWhitespace(string $character) : bool
public static matchAt(string $regex, string $string, int $offset = 0) : ?int
 

Attempt to match a regex in string s at offset offset

  • psalm-param non-empty-string $regex
  • return int|null Index of match, or null
  • psalm-pure
public static matchFirst(string $pattern, string $subject, int $offset = 0) : ?array
 

Functional wrapper around preg_match_all which only returns the first set of matches

  • psalm-param non-empty-string $pattern
  • return string[]|null
  • psalm-pure
public static unescape(string $string) : string
 

Replace backslash escapes with literal characters

  • psalm-pure
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration