Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rschrieken/77573a53e0f0061a84ac to your computer and use it in GitHub Desktop.
Save rschrieken/77573a53e0f0061a84ac to your computer and use it in GitHub Desktop.

Reference - What does this regex mean?

What is this?

This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining it.

Why is this?

[tag:regex] is suffering from give me ze code type of questions and poor answers with no explanation. This reference is meant to provide links to quality Q&A.

What's the scope?

This reference is meant for the following languages: [tag:php], [tag:perl], [tag:javascript], [tag:python], [tag:ruby], [tag:java], [tag:.net].
This might be too broad, but these languages share the same syntax. For specific features there's the tag of the language behind it, example:

  • What are regular expression Balancing Groups? [tag:.net]

The list

Quantifiers:

Character classes:

  • How does a character class [] work?
  • How does a negated character class [^] work?
  • How does a substraction in character classes [range-[bar]] work? [tag:java], [tag:ruby] 1.9+
  • How does intersection in character classes [range&&[bar]] work? [tag:java], [tag:ruby] 1.9+
  • How does POSIX character classes [:alpha:] work?
  • Why [^\\D2], [^[^0-9]2], [^2[^0-9]] get different results in Java? [tag:java]

Anchors:

  • What does ^ mean?
  • What does $ mean?
  • What does \A mean? [tag:php], [tag:perl], [tag:python], [tag:ruby]
  • What does \Z mean? [tag:php], [tag:perl], [tag:python], [tag:ruby]
  • What does \G mean? [tag:php], [tag:perl], [tag:ruby]
  • What does \b and \B mean? word boundaries

Groups:

  • What does a capturing group () mean?
  • What does a backreference \1 mean?
  • What does a non capturing group (?:) mean?
  • What does an atomic group (?>) mean?
  • What does branch reset (?|) mean?
  • How does named groups work ? comment: since there are differences, we need to split this up
  • [tag:php] (?P<groupname>regex), (?<groupname>regex)
  • [tag:python] (?P<groupname>regex)
  • [tag:.net] ...
  • [tag:perl] ...

Lookaround:

Modifiers:

Escape sequence:

  • What does \d mean?
  • What does \D mean?
  • What does \w mean?
  • What does \W mean?
  • What does \s mean?
  • What does \S mean?
  • What does \h mean?
  • What does \H mean?
  • What does \v mean?
  • What does \V mean?
  • What does \t mean?
  • What does \r mean?
  • What does \n mean?
  • What does \e mean?
  • What does \R mean? [tag:php]

Other: not sure about the name ...

Control verbes: [tag:php] [tag:perl]

  • What does (*PRUNE) mean?
  • What does (*SKIP) mean?
  • What does (*FAIL)/(*F) mean?
  • What does (*COMMIT) mean?
  • What does (*MARK) mean?
  • What does (*THEN) mean?
  • What does (*ACCEPT) mean?

Recursion: [tag:php] [tag:perl]

  • What does (?R) mean?
  • What does (?0), (?1) mean?
  • What does (?-1) mean?
  • What does (?P>groupname)/(?&groupname) mean?

Advanced regex-fu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment