Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
system:regex:regex_notation [2017/09/19 10:58] smayr created |
system:regex:regex_notation [2018/04/13 11:52] (current) smayr [Regex Quick Reference] |
||
---|---|---|---|
Line 2: | Line 2: | ||
== Regex Quick Reference == | == Regex Quick Reference == | ||
- | [abc] | + | ^ Symbol |
- | [^abc] | + | | [abc] |
- | [a-z] | + | | [< |
- | [a-zA-Z] | + | | [a-z] |
- | ^ | + | | [a-zA-Z] |
- | $ End of line | + | | < |
- | \A Start of string | + | | . |
- | \z End of string | + | | \s | Any whitespace character |
- | . | + | | \S | Any non-whitespace character |
- | \s | + | | \d | Any digit | |
- | \S | + | | \D | Any non-digit |
- | \d | + | | \w | Any word character (letter, number, underscore) |
- | \D | + | | \W | Any non-word character |
- | \w | + | | (...) |
- | \W | + | | (a< |
- | \b Any word boundary character | + | | a? | Zero or one of a | |
- | (...) | + | | a* | Zero or more of a | |
- | (a|b) | + | | a+ | One or more of a | |
- | a? | + | | a{3} | Exactly 3 of a | |
- | a* | + | | a{3,} |
- | a+ | + | | a{3, |
- | a{3} | + | |
- | a{3,} | + | |
- | a{3, | + | |
- | options: | + | General Tokens: |
- | i case insensitive | + | ^ Symbol |
- | | + | | \n | Newline | |
- | x ignore whitespace | + | | \r | Carriage return | |
- | o perform | + | | \t | Tab | |
+ | | \f | Form-feed | | ||
+ | | \0 | Null character | | ||
+ | |||
+ | Anchors: | ||
+ | ^ Symbol | ||
+ | | \G | Start of match | | ||
+ | | < | ||
+ | | \A | Start of string | | ||
+ | | $ | End of string | | ||
+ | | \Z | End of string | | ||
+ | | \z | Absolute end of string | | ||
+ | | \b | Any word boundary character | | ||
+ | | \B | Any non-word boundary | | ||
+ | | \w | Any word character (letter, number, underscore) | | ||
+ | | \W | Any non-word character | | ||
+ | |||
+ | Flags/ | ||
+ | ^ Symbol | ||
+ | | g | Global (do not return after first match) | | ||
+ | | i | Case insensitive | ||
+ | | m | Multiline (dot matches | ||
+ | | s | Single line (dot matches newline) | | ||
+ | | u | Unicode (match with full unicode) | | ||
+ | | x | eXtended (ignore whitespace) | | ||
+ | | X | eXtra (disallow meaningless excapes| | ||
+ | | o | Perform | ||
+ | | A | Anchored (anchor to start of pattern) | | ||
+ | | J | Duplicate group names (allow duplicate subpattern names) | | ||
+ | | D | Dollar end only ($ matches only end of pattern) | | ||
+ | |||
+ | == Using Regex in PHP == | ||
+ | |||
+ | Can be used as '' | ||
+ | <code php> | ||
+ | <?php | ||
+ | if(ereg(' | ||
+ | |||
+ | if(preg_match('/ | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Using options: | ||
+ | <code php> | ||
+ | <?php | ||
+ | // The " | ||
+ | if (preg_match("/ | ||
+ | echo "A match was found."; | ||
+ | } else { | ||
+ | echo "A match was not found."; | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Example using '' | ||
+ | <code php> | ||
+ | // Strip ending commas | ||
+ | $str = preg_replace('/, | ||
+ | |||
+ | // Strip leading/ | ||
+ | $str = preg_replace('/ | ||
+ | </ | ||
+ | |||
+ | == References == | ||
+ | * [[http:// | ||
+ | * [[https:// |