Regular Expressions Cheat Sheet
Uncomplicating the complicated
Make Tech Easier
A regular expression is a specific pattern used in computing that provides concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. ommon abbreviations for "regular expression" include regex and regexp.! Wikipedia
Character
. (dot)
Description
Example
Match any single character, except newline c.t matches "cat", "cut" or "cot." (\n) Repeat the previous expression 0 or more times (greedy mode) Repeat the previous expression 1 or more times. Ma$es the previous item optional. 12*3 matches "1 ", "1! ", "1!! ", "1!!! ". "t can #e used together with . (dot) such as m.*easier to match "ma$etecheasier". 12+3 matches "1! ","1!! ","1!!! " ma?ke matches "ma$e", "m$e"
* (star)
+ (plus) ? (%uestion mar$) ^ (caret) $ (dollar) (...) (round #rac$et)
Match &rom the #eginning ^he matches "hello", "hell", "help", "he is a #oy" o& the string Match &rom the end o& the ed$ matches "acted", #ed", "greed" string 'rouping o& characters or (ak) matches "ma$e", "ta$e", ( expression 12{3}5 matches "1!!!+" 12{3,5}3 matches 12223, 122223, 1222223
{n} (curly Match the previous item #rac$et, where exactly n times n )* 1) {n,m} (n )*1, Match the previous item #etween n and m times m ) n) {n,} (n )*1)
Match the previous item at 12{2,}3 matches 1223, 12223, 122223 least n times a[BC]d matches ,a-cd. or ,a#/d. a[^ ]c matches "aec", "acc", "adc", #ut not "a#c"
[...] (s%uare match any single character in the #rac$et #rac$et) [^...] Match any character except &or those that are de&ined in the #rac$et Match either the expression on the le&t or right o& the pipe.
! (pipe)
c"#("!"$)r matches "color", "colour"
% (hypen) + (#ac$slash)
0peci&y a range o& [a%&] matches all lowercase alpha#et. characters to match. 1sed ['%(] matches all uppercase alpha#et. mostly with s%uare [)%*] matches all the digit 0 to 2. #rac$et. 3scape a special a+*c matches "a4c".
Property of Make Tech Easier ([Link]
Character
+n, +r, +t,+d,, +-,+s
Description
character match a newline, return, ta#, digit, word, whitespace character respectively 5egate version o& +d,, +-,,+s. Match (not digit), (not word), (not whitespace) character respectively.
Example
+.,,+/,,+0
+ ...+
Match a string at the + 1ech+ matches the word "6ech" in the phrase "Ma$e #oundary /an #e used to 6ech 3asier". match a word in a phrase. Match a string not within the #oundary. /an #e ued +B1ech+B matches Tech i! MakeTechEasier, "#t !ot i! to match a string within Make Tech Easier. another string 7hen used inside a s%uare #rac$et, + matches a #ac$space character
+B...+B
[+ ]
8o you li$e this cheat sheet9 :isit Ma$[Link] &or more use&ul tech tutorials, tips and tric$s
Property of Make Tech Easier ([Link]