(Solved) Reference – What does this regex mean?

[ad_1]

The Stack Overflow Regular Expressions FAQ

See also a lot of general hints and useful links at the regex tag details page.


Online tutorials

Quantifiers

  • Zero-or-more: *:greedy, *?:reluctant, *+:possessive
  • One-or-more: +:greedy, +?:reluctant, ++:possessive
  • ?:optional (zero-or-one)
  • Min/max ranges (all inclusive): {n,m}:between n & m, {n,}:n-or-more, {n}:exactly n
  • Differences between greedy, reluctant (a.k.a. “lazy”, “ungreedy”) and possessive quantifier:
    • Greedy vs. Reluctant vs. Possessive Quantifiers
    • In-depth discussion on the differences between greedy versus non-greedy
    • What’s the difference between {n} and {n}?
    • Can someone explain Possessive Quantifiers to me? php, perl, java, ruby
    • Emulating possessive quantifiers .net
    • Non-Stack Overflow references: From Oracle, regular-expressions.info

Character Classes

  • What is the difference between square brackets and parentheses?
  • [...]: any one character, [^...]: negated/any character but
  • [^] matches any one character including newlines javascript
  • [\w-[\d]] / [a-z-[qz]]: set subtraction .net, xml-schema, xpath, JGSoft
  • [\w&&[^\d]]: set intersection java, ruby 1.9+
  • [[:alpha:]]:POSIX character classes
  • [[:<:]] and [[:>:]] Word boundaries
  • Why do [^\\D2], [^[^0-9]2], [^2[^0-9]] get different results in Java? java
  • Shorthand:
    • Digit: \d:digit, \D:non-digit
    • Word character (Letter, digit, underscore): \w:word character, \W:non-word character
    • Whitespace: \s:whitespace, \S:non-whitespace
  • Unicode categories (\p{L}, \P{L}, etc.)

Escape Sequences

  • Horizontal whitespace: \h:space-or-tab, \t:tab
  • Newlines:
    • \r, \n:carriage return and line feed
    • \R:generic newline php java-8
  • Negated whitespace sequences: \H:Non horizontal whitespace character, \V:Non vertical whitespace character, \N:Non line feed character pcre php5 java-8
  • Other: \v:vertical tab, \e:the escape character

Anchors

anchormatchesflavors
^Start of stringCommon*
^Start of lineCommonm
$End of lineCommonm
$End of textCommon* except javascript
$Very end of stringjavascript*, phpD
\AStart of stringCommon except javascript
\ZEnd of textCommon except javascript python
\ZVery end of stringpython
\zVery end of stringCommon except javascript python
\bWord boundaryCommon
\BNot a word boundaryCommon
\GEnd of previous matchCommon except javascript, python
TermDefinition
Start of stringAt the very start of the string.
Start of lineAt the very start of the string, and
after a non-terminal line terminator.
Very end of stringAt the very end of the string.
End of textAt the very end of the string, and
at a terminal line terminator.
End of lineAt the very end of the string, and
at a line terminator.
Word boundaryAt a word character not preceded by a word character, and
at a non-word character not preceded by a non-word character.
End of previous matchAt a previously set position, usually where a previous match ended.
At the very start of the string if no position was set.

“Common” refers to the following: icu java javascript .net objective-c pcre perl php python swift ruby

* Default |
m Multi-line mode. |
D Dollar end only mode.

Groups

  • (...):capture group, (?:):non-capture group
    • Why is my repeating capturing group only capturing the last match?
  • \1:backreference and capture-group reference, $1:capture group reference
    • What’s the meaning of a number after a backslash in a regular expression?
    • \g<1>123:How to follow a numbered capture group, such as \1, with a number?: python
  • What does a subpattern (?i:regex) mean?
  • What does the ‘P’ in (?P<group_name>regexp) mean?
  • (?>):atomic group or independent group, (?|):branch reset
    • Equivalent of branch reset in .NET/C# .net
  • Named capture groups:

Lookarounds

  • Lookaheads: (?=...):positive, (?!...):negative
  • Lookbehinds: (?<=...):positive, (?<!...):negative
  • Lookbehind limits in:
    • Lookbehinds need to be constant-length php, perl, python, ruby
    • Lookarounds of limited length {0,n} java
    • Variable length lookbehinds are allowed .net
  • Lookbehind alternatives:
    • Using \K php, perl (Flavors that support \K)
    • Alternative regex module for Python python
      • The hacky way
      • JavaScript negative lookbehind equivalents External link

Modifiers

flagmodifierflavors
aASCIIpython
ccurrent positionperl
eexpressionphp perl
gglobalmost
icase-insensitivemost
mmultilinephp perl python javascript .net java
m(non)multilineruby
oonceperl ruby
Sstudyphp
ssingle lineruby
Uungreedyphp r
uunicodemost
xwhitespace-extendedmost
ysticky ↪javascript
  • How to convert preg_replace e to preg_replace_callback?
  • What are inline modifiers?
  • What is ‘?-mix’ in a Ruby Regular Expression

Other:

  • |:alternation (OR) operator, .:any character, [.]:literal dot character
  • What special characters must be escaped?
  • Control verbs (php and perl): (*PRUNE), (*SKIP), (*FAIL) and (*F)
    • php only: (*BSR_ANYCRLF)
  • Recursion (php and perl): (?R), (?0) and (?1), (?-1), (?&groupname)

Common Tasks

  • Get a string between two curly braces: {...}
  • Match (or replace) a pattern except in situations s1, s2, s3…
  • How do I find all YouTube video ids in a string using a regex?
  • Validation:
    • Internet: email addresses, URLs (host/port: regex and non-regex alternatives), passwords
    • Numeric: a number, min-max ranges (such as 1-31), phone numbers, date
    • Parsing HTML with regex: See “General Information > When not to use Regex”

Advanced Regex-Fu

  • Strings and numbers:
    • Regular expression to match a line that doesn’t contain a word
    • How does this PCRE pattern detect palindromes?
    • Match strings whose length is a fourth power
    • How does this regex find triangular numbers?
    • How to determine if a number is a prime with regex?
    • How to match the middle character in a string with regex?
  • Other:
    • How can we match a^n b^n?
    • Match nested brackets
      • Using a recursive pattern php, perl
      • Using balancing groups .net
    • “Vertical” regex matching in an ASCII “image”
    • List of highly up-voted regex questions on Code Golf
    • How to make two quantifiers repeat the same number of times?
    • An impossible-to-match regular expression: (?!a)a
    • Match/delete/replace this except in contexts A, B and C
    • Match nested brackets with regex without using recursion or balancing groups?

Flavor-Specific Information

(Except for those marked with *, this section contains non-Stack Overflow links.)

General information

(Links marked with * are non-Stack Overflow links.)

Examples of regex that can cause regex engine to fail

  • Why does this regular expression kill the Java regex engine?

Tools: Testers and Explainers

(This section contains non-Stack Overflow links.)

3

[ad_2]

solved Reference – What does this regex mean?