Complete list of regular expression examples : Regular Expressions « String « PHP






Complete list of regular expression examples

 
Expression                    Will match . . .
 
foo                           The string "foo"
 
^foo                          "foo" at the start of a line
 
foo$                          "foo" at the end of a line
 
^foo$                         "foo" when it is alone on a line
 
[Ff]oo                        "Foo" or "foo"
 
[abc]                         a, b, or c
 
[^abc]                        d, e, f, g, V, %, ~, 5, etc.everything that is not a, b, or c (^ is "not" inside character classes)
 
[A-Z]                         Any uppercase letter
 
[a-z]                         Any lowercase letter
 
[A-Za-z]                      Any letter
 
[A-Za-z0-9]                   Any letter or number
 
[A-Z]+                        One or more uppercase letters
 
[A-Z]*                        Zero or more uppercase letters
 
[A-Z]?                        Zero or one uppercase letters
 
[A-Z]{3}                      Three uppercase letters
 
[A-Z]{3,}                     A minimum of three uppercase letters
 
[A-Z]{1,3}                    One, two, or three uppercase letters
 
[^0-9]                        Any non-numeric character
 
[^0-9A-Za-z]                  Any symbol (not a number or a letter)
 
(cat|sat)                     Matches either "cat" or "sat"
 
([A-Z]{3}|[0-9]{4})           Matches three letters or four numbers
 
Fo*                           F, Fo, Foo, Fooo, Foooo, etc.
 
Fo+                           Fo, Foo, Fooo, Foooo, etc.
 
Fo?                           F, Fo
 
.                             Any character except \n (new line)
 
\b                            A word boundary; e.g. te\b matches the "te" in "late" but not the "te" in "tell."
 
\B                            A non-word boundary; "te\B" matches the "te" in "tell" but not the "te" in "late."
 
\n                            Newline character
 
\s                            Any whitespace (new line, space, tab, etc.)
 
\S                            Any non-whitespace character
  
  








Related examples in the same category

1.Brackets [] finds a range of characters.
2.Character Classes
3.\b and \B, equate to "On a word boundary" and "Not on a word boundary," respectively.
4.^ and $ are line anchors.
5.Line Anchors
6.Match URL
7.Match an IP address
8.Match the smallest number of characters starting with "p" and ending with "t"
9.Matching GUIDs/UUIDs
10.Matching a Valid E-mail Address
11.Matching a Valid IP Address
12.Matching using backreferences
13.Matching with Greedy vs. Nongreedy Expressions
14.Matching with character classes and anchors
15.Matching with |
16.Define a pattern and use parentheses to match individual elements within it
17.Greedy Qualifiers
18.Greedy and non-greedy matching
19.Greedy versus nongreedy matching
20.Grouping captured subpatterns
21.Validating Pascal Case Names
22.Validating U.S. Currency
23.Validating a credit card number
24.Nongreedy Qualifiers
25.POSIX Regular Expressions Character Classes
26.POSIX Regular Expressions Character Classes
27.Ranges
28.Option patterns:
29.Predefined Character Ranges (Character Classes)
30.Pattern matches:
31.Pattern match extenders:
32.Perl-Compatible Regular Expressions (PCRE)
33.Qualifiers restrict the number of times the preceding expression may appear.
34.Quantifiers for Matching a Recurring Character
35.Quantifiers: +, *, ?, {int. range}, and $ follow a character sequence:
36.Special classes for regular expression
37.Regular expressions using character classes