Regular Expressions 101

Community Patterns

13/11/2019

0

Regular Expression
PCRE (PHP <7.3)

/
(?############# ### AS PHP ### ##############) (?##################################################### ### DECLEAR GROUPS CAPTURE NAME WITHOUT USING THEM ### #######################################################) (?(DEFINE) (?<_VAR_NAME>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*) (?# Valid variable name) (?<_BOOLEAN>(?i:false|true)) (?# Valid boolean value) (?<_STRING>(?:"(?:[\\\\]+.|[^"])*")|(?:\'(?:[\\\\]+.|[^\'])*\')) (?# Valid string value) (?<_INT>[0-9]+) (?# Valid integer value) (?<__INT>(?:(?:-|\+)\s*)?(?P>_INT)) (?# Valid positive or negative interger value) (?<_KEY>(?P>_STRING)|(?P>_INT)|(?P>_CALL)) (?# Valid key name) (?<__KEY>(?:\[(?P>_KEY)\])+) (?# Valid multiple keys) (?<_CALL>\$(?P>_VAR_NAME)(?P>__KEY)?) (?# Valid variable calls) (?<_VALUE>(?i:null)|(?P>_BOOLEAN)|(?P>_STRING)|(?P>__INT)|(?P>_CALL)) (?# Valid value without array value) (?<_ARRAY>\[\s*(?:(?:(?:(?P>_VALUE)|(?P>_ARRAY))\s*,\s*)*(?:(?:(?P>_VALUE)|(?P>_ARRAY))\s*))?\])(?# Valid array) (?<__VALUE>(?:(?P>_VALUE)|(?P>_ARRAY))) (?# Valid value with array value) (?<_OPERATORS>={2,3}|!={1,2}|>=?|<=?) (?# Valid operators signs) (?<_SHORT_OPR>AND|OR|and|or|&{2}|\|{2}) (?# Valid short-handed opreators signs) ) (?##################### ### START CAPTURE ### #######################) (?# Get the full match capture text) (?:<!--(?s:.)+?-->|<!--(?s:.)*)(*SKIP)(*FAIL)| (?# SKIP ON COMMENTS FOUND) (?#[^\\\\](?:[\\\\]{2})(?#*[\\\\](?P>text)(?#(*SKIP)(?#(*FAIL)(?#| (?# SKIP ESCAPED MATCHES) (?<text> (?# Find new variables declare with multiple keys - mark as SET) (*:SET) (?<target>\$(?<name>(?P>_VAR_NAME))(?<key>(?P>__KEY))?) (?:(?<A>)|(?<B>\s*)) (?<operator> (?(B) (?:(?<C>\+=|-=)|(?<D>\.=|=\.)) |(?(A) (?<E>\+{2}|\-{2})) ) ) (?(E)|(?:\s*(?<value> (?(B)(?P>__VALUE)| (?(C)(?:(?P>__INT)|(?P>_CALL))| (?(D)(?:(?P>_STRING)|(?P>_CALL))) ) ) ))); (?########## OR ##########)| (?# Find new variables declare with multiple keys - mark as SET) (*:SET) (?<target>\$(?<name>(?P>_VAR_NAME))(?<key>(?P>__KEY))?)\s*=\s*(?<value>(?P>__VALUE)); (?########## OR ##########)| (?# Find variable calls with multiple keys - mark as CALL) (*:CALL) (?<target>\$(?<name>(?P>_VAR_NAME))(?<key>(?P>__KEY))?) (?########## OR ##########)| (?# Find conditional statements - mark as IF) (*:IF) (?i)(?:if)(?-i)\s* \((?<statements>(?P>_VALUE)(?:\s*(?P>_OPERATORS)\s*(?P>_VALUE)(?!(?P>_OPERATORS))|(?:\s+(?P>_SHORT_OPR)\s+(?P>_VALUE))*)+)\)\s*{ (?<content>(?:|(?R)|.|\s)*) } (?########## OR ##########)| (?# Find while loops - mark as WHILE) (*:WHILE) (?i)(?:while)(?-i)\s* \((?<statements>(?P>_VALUE)(?:\s*(?P>_OPERATORS)\s*(?P>_VALUE)(?!(?P>_OPERATORS))|(?:\s+(?P>_SHORT_OPR)\s+(?P>_VALUE))*)+)\)\s*{ (?<content>(?:|(?R)|.|\s)*) } )
/
gmxJ

Description

Almost ready!!!

Submitted by anonymous - 4 years ago