From: Rich Bowen
The following are the minimal building blocks you will need, in order
-to write regular expressions and RewriteRule
s.
RewriteRule
s. They certainly do not
+represent a complete regular expression vocabulary, but they are a good
+place to start, and should help you read basic regular expressions, as
+well as write your own.
Character | Meaning | +Example |
---|---|---|
. | Matches any character | |
. | Matches any +character | c.t will match cat ,
+cot , cut , etc. |
+ | Repeats the previous match one or more +times | a+ matches a , aa ,
+aaa , etc |
* | Repeats the previous match zero or more +times. | a* matches all the same things
+a+ matches, but will also match an empty string. |
? | Makes the match optional. | |
. | Matches any +character | colou?r will match color and
+colour . |
^ | Called an anchor, matches the beginning +of the string | ^a matches a string that begins with
+a |
$ | The other anchor, this matches the end of +the string. | a$ matches a string that ends with
+a . |
( ) | Groups several characters into a single +unit, and captures a match for use in a backreference. | (ab)+
+matches ababab - that is, the + applies to the group.
+For more on backreferences see below. |
[ ] | A character class - matches one of the +characters | c[uoa]t matches cut ,
+cot or cat . |
! | Not | Negates a match - that is, +ensures that it does not match. |
The following are the minimal building blocks you will need, in order
to write regular expressions and
Character | Meaning | +Example |
---|---|---|
. | Matches any character | |
. | Matches any +character | c.t will match cat ,
+cot , cut , etc. |
+ | Repeats the previous match one or more +times | a+ matches a , aa ,
+aaa , etc |
* | Repeats the previous match zero or more +times. | a* matches all the same things
+a+ matches, but will also match an empty string. |
? | Makes the match optional. | |
. | Matches any +character | colou?r will match color and
+colour . |
^ | Called an anchor, matches the beginning +of the string | ^a matches a string that begins with
+a |
$ | The other anchor, this matches the end of +the string. | a$ matches a string that ends with
+a . |
( ) | Groups several characters into a single +unit, and captures a match for use in a backreference. | (ab)+
+matches ababab - that is, the + applies to the group.
+For more on backreferences see below. |
[ ] | A character class - matches one of the +characters | c[uoa]t matches cut ,
+cot or cat . |
! | Not | Negates a match - that is, +ensures that it does not match. |