Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
system:regex:regex_notation [2018/04/13 11:10]
smayr [Using Regex in PHP]
system:regex:regex_notation [2018/04/13 11:52] (current)
smayr [Regex Quick Reference]
Line 8: Line 8:
 | [a-zA-Z]     | Any single character in the range a-z or A-Z | | [a-zA-Z]     | Any single character in the range a-z or A-Z |
 | <nowiki>^</nowiki>            | Start of line | | <nowiki>^</nowiki>            | 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<nowiki>|</nowiki>b)        | a or b | | (a<nowiki>|</nowiki>b)        | a or b |
Line 28: Line 24:
 | a{3,6}       | Between 3 and 6 of a | | a{3,6}       | Between 3 and 6 of a |
  
-Options+General Tokens: 
 +^ Symbol       ^ Description ^ 
 +| \n           | Newline | 
 +| \r           | Carriage return | 
 +| \t           | Tab | 
 +| \f           | Form-feed | 
 +| \0           | Null character | 
 + 
 +Anchors: 
 +^ Symbol       ^ Description ^ 
 +| \G           | Start of match | 
 +| <nowiki>^</nowiki>            | Start of string | 
 +| \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/Modifiers (eg: "/regex here.../g"): 
 +^ Symbol       ^ Description  ^  
 +| g  | Global (do not return after first match) |
 | i  | Case insensitive | | i  | Case insensitive |
-| m  | Make dot match newlines +| m  | Multiline (dot matches newlines, <nowiki>^</nowiki> and $ match start/end of line)  
-| x  | Ignore whitespace in regex +| s  | Single line (dot matches newline) | 
 +| u  | Unicode (match with full unicode) |  
 +| x  | eXtended (ignore whitespace) |  
 +| 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 59: Line 84:
 Example using ''preg_replace()'': Example using ''preg_replace()'':
 <code php> <code php>
 +// Strip ending commas
 +$str = preg_replace('/,$/s', '', $str);
 +
 // Strip leading/trailing commas with whitespace around // Strip leading/trailing commas with whitespace around
 $str = preg_replace('/^[,\s]+|[\s,]+$/', '', $str); $str = preg_replace('/^[,\s]+|[\s,]+$/', '', $str);
 </code> </code>
 +
 +== References ==
 +  * [[http://www.rexegg.com/regex-quickstart.html|Regex Cheat Sheet]]
 +  * [[https://regex101.com|Regex 101]]