Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/CloudIngenium.com/htdocs/wp-includes/functions.php on line 6114
How to write a Regular Expression – syntax – Knowledge eXchange

How to write a Regular Expression – syntax

Q: What are the special characters, escape sequences, and in general the syntax when doing regex (Regular Expressions)?

A:

. any character except a newline

d any decimal digit
D any non-digit
s any whitespace character
S any non-whitespace characte
w any alphanumeric character
W any non-alphanumeric character
number the contents of the group with the given number
* zero or more of the preceding block
*? zero or more of the preceding block (non-greedy)
+ one or more of the preceding block
+? one or more of the preceding block (non-greedy)
+ zero or one of the preceding block
+? zero or one of the preceding block (non-greedy)
{m} exactly m copies of the preceding block
{m, n} m to n copies of the preceding block
{m, n}? m to n copies of the preceding block (no-greedy)
^ beginning of line
$ end of line
b word boundary
B non-word boundary
(…) group
(?:…) non-grouping group
(?=…) matches if <…> matches next, but does not consume the string
(?!…) matches if <…> does NOT match next, but does not consume the string
x|y matches x or y
[xyz] matches any one of x, y or z
[^xyz] matches any character except x, y or z
[a-z] matches any one character between a and z
[^a-z] matches any one character except the characters between a and z

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.