Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active December 10, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Potherca/1708b28f5515d0b56aa4e118d6c69086 to your computer and use it in GitHub Desktop.
Save Potherca/1708b28f5515d0b56aa4e118d6c69086 to your computer and use it in GitHub Desktop.
A list of capturing and non-capturing groups avaiable in regular expressions

Groups in regular expressions (Capturing and non-capturing)

In regular expressions groups can be used. Different types of groups have different notations.

These notations sometimes only differ as little as one character. This can be confusing.

To make it easier to distinguish between the different group types, they are all listen here.

Overview

The following groups are available in Regular expressions:

  • (…) Capturing group and (?<…>…) named capturing group
  • (?:…) Non-capturing group
  • (?!…) Negative Lookahead
  • (?=…) Positive Lookahead
  • (?<!…) Negative Lookbehind
  • (?<=…) Positive Lookbehind

Lookahead and lookbehind are also non-capturing groups. Together they are known as "lookarounds".

Syntax diagram of regular expression groups

group
= "("
(
/ "?"
(
"<" "…" ">" /* named capturing group */
/ ":" /* Non-capturing group */
/ "<"? /* Lookbehind */
(
"!" /* Negative Lookahead / Lookbehind */
/ "=" /* Positive Lookahead / Lookbehind */
)
)
)
"…"
")"
;
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment