Skip to content

Instantly share code, notes, and snippets.

@pganti
Created July 3, 2014 05:53
Show Gist options
  • Save pganti/03ece3e9dd926ed7dd7a to your computer and use it in GitHub Desktop.
Save pganti/03ece3e9dd926ed7dd7a to your computer and use it in GitHub Desktop.
regex
. Any char except newline,
? zero or one,
* zero or more,
+ one or more, \+ in vim.
\ quote, match next char literally,
\Number of match of left open paren,
[a-z] in char-class,
[^a-z] not in char class,
---------------------------------------------------------
Emacs Perl Vim
---------------------------------------------------------
\| | | Alternative.
\< \> \b \< \> Word begin/end.
^ $ ^ $ ^ $ Line begin/end.
\` \' \A \Z Buffer begin/end.
\sw \Sw \w \W \w \W Word char, not a word char.
[0-9] \d \D \d \D Digit, not a digit.
\s- \S- \s \S \s \S Space, not a space.
[a-zA-Z] \a \A Alphabetic
[a-z] \l \L Lower, not.
[A-Z] \u \U Upper, not.
+ + \+ One or more.
\{n,m} m..n (greedy).
\( \) ( ) \( \) Grouping.
\1 $1 \1 Group 1 that matched.
\& $& & Whole match for re.
~ Last subst.
:set magic
:help regexp for non-eager.
---------------------------------------------------------
Vim6 Regexp
---------------------------------------------------------
\? 0 or 1 (greedy).
\= 0 or 1 (greedy).
\{n,m} \{-n,m} m..n (greedy,non-greedy).
\{n} \{-n} n (greedy,non-greedy).
\{,m} \{-,m} 0..m (greedy,non-greedy).
* \{-} 0..more (greedy,non-greedy).
\_. [.\n]
\%^ \^# \%$ bof, cursor/point, eof.
\%23l \%23c \23v line 23, column 23, vcolumn 23.
\L \l \U \u \D \d alphabets (not)lower,(not)upper,(not)digit.
\p printable.
Directives
\c \C \M \m \V \v (no)case,(no)magic,(no)very-magic-perl.
---------------------------------------------------------
ksh patterns
---------------------------------------------------------
? Matches one file char except / and a . at the beginning of a file name.
* Matches >= 0, same restrictions as ?.
?(pattern-list) Matches 0,1 of pattern-list.
*(pattern-list) Matches zero or more of pattern-list.
+(pattern-list) Matches >= 1, of pattern-list.
@(pattern-list) Matches == 1, of pattern-list.
!(pattern-list) Matches any string that does not match pattern-list.
---------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment