Last active
November 21, 2023 01:50
-
-
Save cozingo/91a9e77e2c1275aed5b72edb2ba881d6 to your computer and use it in GitHub Desktop.
Regex regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ErrorDocument 404 /errors/400.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\d - digit [0,9] | |
\w - digit, ASCII letter or underscore | |
\s - whitespace, i.e. space, tab, newline(\n), carriage return(\r), vertical tab(Ctrl + K) <-vertical tab not useful anymore | |
\D == [^\d] - 1 character which is not digit | |
\W == [^\w] - 1 character which is not ASCII letter, digit and underscore | |
\S == [^\s] - 1 character which is not type of whitespace | |
--------------------------------------------------------------------------------------- | |
^ - Start of string, Ex : ^abc accept if string starts with abc | |
$ - End of string or end of line, Ex: .*? the end$ -> this is the end | |
. - Any character except \n (line break) | |
\ - Escape character for reserved words. Ex : 1) \.\*\+\? \$\^\/\\ -> *+? $^/\ 2) \[\{\(\)\}\] -> [{()}] | |
? - 1 time on none Ex : plurals? plural | |
* - 0 or more Ex: A*B*C* AAACC | |
+ - 1 or more | |
--------------------------------------------------------------------------------------- | |
{3} - exactly 3 times, Ex: \D{3} -> ABC | |
{2,4} - 2 to 4 times, Ex: \d{2,4} -> 156 | |
{3,} - 3 or more times Ex: \w{3,} regex_tutorial | |
--------------------------------------------------------------------------------------- | |
| - OR operand, Ex: 22|33 -> 33 | |
(…) - Capturing group, Ex: A(nt|pple) -> Apple (captures "pple") | |
\1 - Type of First Group parantheses, Ex: r(\w)g\1x -> regex(Here is \1 is type of \w) | |
\2 - Type of Second Group parantheses, (\d\d)\+(\W\d)=\2\+\1 -> 12+,5=,5+12(Here is \1 is type of \d\d and \2 is type of \W\d) | |
(?:…) - Non-capturing group, Ex: A(?:nt|pple) -> Apple(Here is pple or not "nt" is acceptable) | |
-------------------------------------------------------------------------------------- | |
[ … ] - One of the characters in the brackets, Ex: 1)[AEIOU] -> 1 uppercase vowel 2) T[ao]p -> Tap or Top | |
- - Range indicator, Ex: [a-z] -> 1 lowercase letter | |
Ex: [x-y] - One of the characters in the range from x to y | |
[^x] - One character that is not x | |
[^x-y] - One of the characters not in the range from x to y | |
-------------------------------------------------------------------------------------- | |
\t - tab character, Ex: T\t\w{2} -> T ab | |
\r - carriage return | |
\n - Line feed | |
\r\n - Line separator on Windows | |
\h - 1 horizontal whitespace character: tab or Unicode space separator | |
\N - [^\n] 1 character is not \n | |
\H - [^\h] 1 character is not \h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.regextester.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%1 Refers to a pattern matched in a RewriteCond condition | |
$1 refers to a pattern matched inside a RewriteRule. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment