Regex syntax: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(update table) |
(fix bug) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
! sed (GNU) |
! sed (GNU) |
||
! vim |
! vim |
||
! less (GNU) |
|||
! python |
! python |
||
|+ |
|+ |
||
Line 15: | Line 16: | ||
| <tt>\(</tt> ... <tt>\)</tt> |
| <tt>\(</tt> ... <tt>\)</tt> |
||
| <tt>\(</tt> ... <tt>\)</tt> |
| <tt>\(</tt> ... <tt>\)</tt> |
||
| <tt>(</tt> ... <tt>)</tt> |
|||
| <tt>(</tt> ... <tt>)</tt> |
| <tt>(</tt> ... <tt>)</tt> |
||
|+ |
|+ |
||
Line 21: | Line 23: | ||
| <tt><nowiki>\|</nowiki></tt> |
| <tt><nowiki>\|</nowiki></tt> |
||
| <tt><nowiki>\|</nowiki></tt> |
| <tt><nowiki>\|</nowiki></tt> |
||
| <tt><nowiki>|</nowiki></tt> |
|||
| <tt><nowiki>|</nowiki></tt> |
| <tt><nowiki>|</nowiki></tt> |
||
|+ |
|+ |
||
| word boundary |
| word boundary |
||
| <tt>\<</tt> or <tt>\></tt> |
|||
| <tt>\<</tt> or <tt>\></tt> |
| <tt>\<</tt> or <tt>\></tt> |
||
| <tt>\<</tt> or <tt>\></tt> |
| <tt>\<</tt> or <tt>\></tt> |
||
| <tt>\<</tt> or <tt>\></tt> |
| <tt>\<</tt> or <tt>\></tt> |
||
| <tt>\b</tt> |
| <tt>\b</tt> |
||
|+ |
|||
| zero or one |
|||
| <tt>\?</tt> |
|||
| <tt>\?</tt> |
|||
| <tt>\?</tt> |
|||
| <tt>?</tt> |
|||
| <tt>?</tt> |
|||
|+ |
|+ |
||
| zero or more |
| zero or more |
||
| <tt>*</tt> |
|||
| <tt>*</tt> |
| <tt>*</tt> |
||
| <tt>*</tt> |
| <tt>*</tt> |
||
Line 39: | Line 51: | ||
| |
| |
||
| <tt>\{-}</tt> |
| <tt>\{-}</tt> |
||
| (unknown) |
|||
| <tt>*?</tt> |
| <tt>*?</tt> |
||
|+ |
|+ |
||
Line 45: | Line 58: | ||
| <tt>\+</tt> |
| <tt>\+</tt> |
||
| <tt>\+</tt> |
| <tt>\+</tt> |
||
| <tt>+</tt> |
|||
| <tt>+</tt> |
| <tt>+</tt> |
||
|+ |
|+ |
||
Line 51: | Line 65: | ||
| |
| |
||
| <tt>\{-1,}</tt> |
| <tt>\{-1,}</tt> |
||
| (unknown) |
|||
| <tt>+?</tt> |
| <tt>+?</tt> |
||
|} |
|} |
||
== References == |
|||
* https://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html |
|||
* http://vimregex.com/ |
|||
* https://docs.python.org/3/library/re.html |
|||
[[Category:Programming]] |
[[Category:Programming]] |
||
[[Category:Cheat sheets]] |
Latest revision as of 08:14, 20 May 2020
- This article is currently a stub; it means I'm aware it's short and I probably intend to expand on the subject in the future!
I can never remember which programs use which regex variants, so here's a quick recap sheet.
grep (GNU) | sed (GNU) | vim | less (GNU) | python | |
---|---|---|---|---|---|
capture | \( ... \) | \( ... \) | \( ... \) | ( ... ) | ( ... ) |
option | \| | \| | \| | | | | |
word boundary | \< or \> | \< or \> | \< or \> | \< or \> | \b |
zero or one | \? | \? | \? | ? | ? |
zero or more | * | * | * | * | * |
zero or more (non-greedy) | \{-} | (unknown) | *? | ||
one or more | \+ | \+ | \+ | + | + |
one or more (non-greedy) | \{-1,} | (unknown) | +? |