Regex Cheatsheet
Regex Cheatsheet
Regex Cheatsheet
+ : Match the last ”block” one or more times ba+ = ba & baa & baaa…
? : any character ba? = b | a
^ : matches the starting line Basic | Bass | Based | Batido = Ba^
$ : Matches the ending position of the string, av? = microwave; ave
it matches the ending position of any line lo? = love; lov, lopez; lop
\s : it matches the spaces
\S : Matches any non-whitespace. Hola yo soy = holayosoy
\d : Matches any digit Numeros
\D : Matches any non-digit. Quita numeros
\w : Matches any word. Cualquier palabra
\W : Matches any non-word. Quita cualquier palabra
\b : Matches any word boundary.
\B : Matches any non-word boundary.
Character classes
. any character except newline
Example;
abc = a.c
[abc] any of a, b, or c
[^abc] not a, b, or c
Anchors
^abc$ start / end of the string
\b\B word, not-word boundary
Escaped characters
\.\*\\ escaped special characters
\t\n\r tab, linefeed, carriage return
Groups & Lookaround
(abc) capture group
\1 backreference to group #1
(?:abc) non-capturing group
(?=abc) positive lookahead
(?!abc) negative lookahead
Quantifiers & Alternation
a*a+a? 0 or more, 1 or more, 0 or 1
a{5}a{2,} exactly five, two or more
a{1,3} between one & three
a+?a{2,}? match as few as possible
ab|cd match ab or cd
Comandos
cut
-d delimiter : usar el delimitador como delimitar una área en vez del tab
grep
-r : search recursively
-n : prefix each line of output with the line number within its input file.
awk
awk pattern {action}
awk patterns may be one of the following
BEGIN : special pattern which is not tested against input. Mostly used for preprocessing, setting
constants, etc. before input is read.
END : special pattern which is not tested against input. Mostly used for postprocessing after input
has been read.
/regular expression/ : the associated regular expression is matched to each input line that
is read
&& : logical AND operator used as pattern1 && pattern2. Execute action if pattern1 and pattern2
are true
! : logical NOT operator used as !pattern. Execute action if pattern is not matched
?: : Used as pattern1 ?
pattern2 : pattern3. If pattern1 is true use pattern2 for testing else use pattern3
pattern1, pattern2 : Range pattern, match all records starting with record that matches pattern1
continuing until a record has been reached that matches pattern2
\\ : Literal backslash
\n : newline
\r : carriage-return
\t : horizontal tab
\v : vertical tab
%e,%E : floating point number of the form [-]d.dddddd.e[±]dd. The %E format uses E instead of e.
%s : character string