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:00] smayr |
system:regex:regex_notation [2018/04/13 11:52] (current) smayr [Regex Quick Reference] |
||
---|---|---|---|
Line 4: | Line 4: | ||
^ Symbol | ^ Symbol | ||
| [abc] | A single character: a, b or c | | | [abc] | A single character: a, b or c | | ||
- | | [^abc] | + | | [< |
| [a-z] | Any single character in the range a-z | | | [a-z] | Any single character in the range a-z | | ||
| [a-zA-Z] | | [a-zA-Z] | ||
- | | ^ | Start of line | | + | | < |
- | | $ | 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|b) | a or b | | + | | (a< |
| a? | Zero or one of a | | | a? | Zero or one of a | | ||
| a* | Zero or more of a | | | a* | Zero or more of a | | ||
Line 28: | Line 24: | ||
| 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:// |