Regular expressions

From PenguinMod Wiki
Revision as of 07:22, 2 July 2024 by Steve0Greatness (talk | contribs) (Steve0Greatness moved page User:Steve0Greatness/drafts/Regular expression to User:Steve0Greatness/drafts/Regular expression: better displays what the page is used for.)
Jump to navigation Jump to search
Lorem ipsum first paragraph where every consonant-vowel pair is highlighted
The alternating yellow and orange highlights show results for the following regexp pattern: /[a-z](?<![aeiou])[aeiou]/gi (any consonant-vowel pair)

Regular expression, often shorted to regex, is a standard

Syntax

x, y, and z when used under symbols are placeholders for text. Capital Xs, Ys, and Zs are used for number placeholders.

Symbol(s) Name Description Example
Groups and backreferences
(x) Capture group Separates the content in the output. "Foo Bar" /(Foo)|(Bar)/g -> [ "Foo", "Bar" ]
(?:x) Non-capture group Acts as if the parentheses were not there "Foo Bar" /(?:Foo)|(?:Bar)/g -> [ "Foo Bar" ]
(?<y>x) Named capture group Equivalent to (x), except it remembers the content used. "Foo Bar" /(?<F>Foo)|(?<B>Bar)/g -> [ "Foo", "Bar" ]
\k<y> Named backreference References a previous named capture group "Foo Foo" /(?<Foo>Foo)\s\k<Foo>/g -> [ "Foo Foo" ]

Flags

Flag Name Description
g global Search all of a string, rather than stopping once you find an occurrence.

See Also