Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
system:regex:regex_notation [2017/09/19 11:09] smayr [Regex Quick Reference] |
system:regex:regex_notation [2018/04/13 11:52] (current) smayr [Regex Quick Reference] |
||
---|---|---|---|
Line 8: | Line 8: | ||
| [a-zA-Z] | | [a-zA-Z] | ||
| < | | < | ||
- | | $ | End of line | | ||
- | | \A | Start of string | | ||
- | | \z | End of string | | ||
| . | Any single character | | | . | Any single character | | ||
| \s | Any whitespace character | | | \s | Any whitespace character | | ||
Line 18: | Line 15: | ||
| \w | Any word character (letter, number, underscore) | | | \w | Any word character (letter, number, underscore) | | ||
| \W | Any non-word character | | | \W | Any non-word character | | ||
- | | \b | Any word boundary character | | ||
| (...) | Capture everything enclosed | | | (...) | Capture everything enclosed | | ||
| (a< | | (a< | ||
Line 28: | Line 24: | ||
| a{3, | | a{3, | ||
- | Options: | + | General Tokens: |
+ | ^ Symbol | ||
+ | | \n | Newline | | ||
+ | | \r | Carriage return | | ||
+ | | \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 | | | i | Case insensitive | | ||
- | | m | Make dot match newlines | + | | m | Multiline (dot matches |
- | | x | Ignore | + | | s | Single line (dot matches newline) | |
+ | | u | Unicode (match with full unicode) | ||
+ | | x | eXtended (ignore | ||
+ | | X | eXtra (disallow meaningless excapes| | ||
| o | Perform #{...} substitutions only once | | | o | Perform #{...} substitutions only once | | ||
+ | | 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 == | == Using Regex in PHP == | ||
Line 44: | Line 69: | ||
?> | ?> | ||
</ | </ | ||
+ | |||
+ | 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:// |