Engine: Glib/GRegex
Home |Engines |Reference |Improve this section
Languages
Features
The following features are supported:
- ✔Flags
- ✔Anchors
- ✔Buffer Boundaries
- ✔Word Boundaries
- ✔Continuation Escape
- ✔Alternatives
- ✔Wildcard
- ✔Character Classes
- ✔Posix Character Classes
- ✔Negated Posix Character Classes
- ✔Character Class Escapes
- ✔Line Endings Escape
- ✔Character Property Escapes
- ✔Quoted Characters
- ✔Quantifiers
- ✔Lazy Quantifiers
- ✔Possessive Quantifiers
- ✔Capturing Groups
- ✔Named Capturing Groups
- ✔Non-Capturing Groups
- ✔Backreferences
- ✔Comments
- ✔Line Comments
- ✔Modifiers
- ✔Lookahead
- ✔Lookbehind
- ✔Non-Backtracking Expressions
- ✔Recursion
- ✔Conditional Expressions
- ✔Subroutines
The following features arenot supported:
- ❌Text Segment Boundaries
- ❌Collating Elements
- ❌Equivalence Classes
- ❌Character Class Nested Set
- ❌Character Class Intersection
- ❌Character Class Union
- ❌Character Class Subtraction
- ❌Character Class Symmetric Difference
- ❌Character Class Complement
- ❌Branch Reset
- ❌Callouts
- ❌Backtracking Control Verbs
Feature: Flags
Main article |Reference |Back to top |Improve this section:1,2
Flags control certain aspects of the matching behavior of a pattern.
Syntax
The following flags are supported:
i— Ignore Case. Matchescharacter classes using a case-insensitive comparison.m— Multiline. Causes theanchors^and$to match the start and end of each line (respectively), rather than the start and end of the input.s— Singleline. Causes thewildcard.to match newline characters.x— Extended Mode. Ignores whitespace in a pattern. Spaces must instead be represented by\sor\(an escaped space).
See Also
Feature: Anchors
Main article |Reference |Back to top |Improve this section:1,2
Anchors match the start or end of a line.
Syntax
^— Matches the start of a line when them(multiline)flag is set. Otherwise, matches the start of the input.$— Matches the end of a line when them(multiline)flag is set. Otherwise, matches the end of the input.
See Also
Feature: Buffer Boundaries
Main article |Reference |Back to top |Improve this section:1,2
ABuffer Boundary is anAtom that matches the start or the end of the input. This differs slightly from^ and$ which can be affected byRegExp flags likem.
Syntax
\A— Matches the start of the input.\z— Matches the end of the input.\Z— A zero-width assertion consisting of an optional newline at the end of the buffer. Equivalent to(?=\n?\z).
See Also
Feature: Word Boundaries
Main article |Reference |Back to top |Improve this section:1,2
AWord Boundary is anAtom that matches the start or the end of a word.
Syntax
\b— Matches the start or the end of a word.\B— Matches whennot at the start or the end of a word.
See Also
Feature: Text Segment Boundaries
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
Feature: Continuation Escape
Main article |Reference |Back to top |Improve this section:1,2
AContinuation Escape is a zero-width assertion that matches either the start of the input or the start of the last match.
Syntax
\G— Matches either the start of the input or the start of the last match.
See Also
Feature: Alternatives
Main article |Reference |Back to top |Improve this section:1,2
AnAlternative represents two or more branches in a pattern. If first branch of a pattern fails to match, each alternative is attempted from left to right until a match is found.
Syntax
…|…— Matches the pattern to the left of the|. If that fails, matches the pattern to the right of|.
Feature: Wildcard
Main article |Reference |Back to top |Improve this section:1,2
AWildcard matches a single, non-newline character.
Syntax
.— Matches any character except newline characters. If thes(single-line)flag is set then this matches any character.
Feature: Character Classes
Main article |Reference |Back to top |Improve this section:1,2
ACharacter Class is anAtom that specifies a set of characters to match a single character in the set.
Syntax
[…]— Where…is one or more single characters or character class escapes, excluding^at the start and-between two entries in the set. Matches a character in the set. Example:[abc]matchesa,b, orc.[^…]— Where…is one or more single characters or character class escapes, excluding-between two entries in the set. Matches any character not in the set. Example:[^abc]matchesd,e, orf, etc., but nota,b, orc.[a-z]— Wherea andz are single characters or character escapes. Matches any character in the range betweena andz (inclusive). Example:[a-c]matchesa,b, orc, but notd.
See Also
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Posix Character Classes
Main article |Reference |Back to top |Improve this section:1,2
APosix Character Class is a member of aCharacter Class set that specifies a named, pre-defined set of characters.
Syntax
[[:name:]]— Wherename is in a set of predefined names. Matches any character in the set.
See Also
- Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Negated Posix Character Classes
Main article |Reference |Back to top |Improve this section:1,2
ANegated Posix Character Class is a member of aCharacter Class set that specifies a named, pre-defined set of excluded characters.
Syntax
[[:^name:]]— Wherename is in a set of predefined names. Matches any character not in the set.
See Also
- Character Classes
- Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Collating Elements
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Equivalence Classes
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Escapes
Main article |Reference |Back to top |Improve this section:1,2
ACharacter Class Escape is a single character escape that represents an entire character class. They can be used as an element of aCharacter Class or as anAtom. It is often the case that a lower-case escape character is the inclusive set, while an upper-case variant of the same character excludes that set.
Syntax
\d— A decimal digit character in the range 0-9. Equivalent to[0-9].\D— Any character not in the range 0-9. Equivalent to[^0-9].\w— Any “word” character. Equivalent to[a-zA-Z0-9_].\W— Any non-“word” character. Equivalent to[^a-zA-Z0-9_].\s— Any whitespace character.\S— Any non-whitespace character.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Line Endings Escape
Main article |Reference |Back to top |Improve this section:1,2
ALine Endings Escape is anAtom that matches any line ending character sequence.
Syntax
\R— Equivalent to(?>\r\n?|[\x0A-\x0C\x85\u{2028}\u{2029}])
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Property Escapes
Main article |Reference |Back to top |Improve this section:1,2
ACharacter Property Escape is an escape sequence used to match a character with a specific character property.
Syntax
\pX— WhereX is a single character. Matches a character that has the propertyX.\p{name}— Wherename is a predefined property name. Matches a character that has the propertyname.\PX— WhereX is a single character. Matches a character that does not have the propertyX.\P{name}— Wherename is a predefined property name. Matches a character that does not have the propertyname.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Nested Set
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Intersection
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Union
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Subtraction
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Symmetric Difference
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Complement
Feature: Character Class Complement
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
Feature: Quoted Characters
Main article |Reference |Back to top |Improve this section:1,2
Quoted Characters are a sequence of characters treated as literal characters rather than RegExp characters.
Syntax
\Q…\E— All characters following\Qand preceding the next\Eare treated as literal characters. Example:\Q.+\Ematches.+but notaa.\Q…— If there is no trailing\E, all characters until the end of the pattern are treated as literal characters.
Feature: Quantifiers
Main article |Reference |Back to top |Improve this section:1,2
Quantifiers specify repetition of anAtom. By default, quantifiers are “greedy” in that they attempt to match as many instances of the precedingAtom as possible to satisfy the pattern before backtracking.
Syntax
*— Matches the precedingAtom zero or more times. Example:a*bmatchesb,ab,aab,aaab, etc.+— Matches the precedingAtom one or more times. Example:a+bmatchesab,aab,aaab, etc., but notb.?— Matches the precedingAtom zero or one times. Example:a?bmatchesb,ab.{n}— Wheren is an integer. Matches the precedingAtom exactlyn times. Example:a{2}matchesaabut notaoraaa.{n,}— Wheren is an integer. Matches the precedingAtom at-leastn times. Example:a{2,}matchesaa,aaa,aaaa, etc., but nota.{n,m}— Wheren andm are integers, andm >=n. Matches the precedingAtom at-leastn times and at-mostm times. Example:a{2,3}matchesaa,aaa,aaaa, etc., but notaoraaaa.
See Also
Feature: Lazy Quantifiers
Main article |Reference |Back to top |Improve this section:1,2
Lazy Quantifiers specify repetition of anAtom, but attempt to match as few instances of the precedingAtom as possible to satisfy the pattern before advancing.
Syntax
*?— Matches the precedingAtom zero or more times.+?— Matches the precedingAtom one or more times.??— Matches the precedingAtom zero or one times.{n}?— Wheren is an integer. Matches the precedingAtom exactlyn times.{n,}?— Wheren is an integer. Matches the precedingAtom at-leastn times.{n,m}?— Wheren andm are integers, andm >=n. Matches the precedingAtom at-leastn times and at-mostm times.
See Also
Feature: Possessive Quantifiers
Main article |Reference |Back to top |Improve this section:1,2
Possessive Quantifiers are like greedy (i.e., regular)quantifiers, except that backtracking is not performed.
Syntax
*+— Match zero or more characters without backtracking.++— Match one or more characters without backtracking.?+— Match zero or one characters without backtracking.{n,}+— Wheren is an integer. Matches the precedingAtom at-leastn times without backtracking.{n,m}+— Wheren andm are integers, andm >=n. Matches the precedingAtom at-leastn times and at-mostm times without backtracking.
See Also
Feature: Capturing Groups
Main article |Reference |Back to top |Improve this section:1,2
ACapturing Group is a subexpression that can be treated as anAtom and can be repeated usingQuantifiers and referenced usingBackreferences by index. A Capturing Group can be captured and returned by the matching algorithm.
Syntax
(…)— Groups the subexpression as a singleAtom. The result is captured and returned by the matching algorithm.
See Also
Feature: Named Capturing Groups
Main article |Reference |Back to top |Improve this section:1,2
ANamed Capturing Group is a subexpression that can be captured and returned by the matching algorithm. A Named Capturing Group is also anAtom and can be repeated usingQuantifiers and referenced usingBackreferences by name.
Syntax
(?<name>…)— Groups the subexpression as a singleAtom associated with the providedname. The result is captured and returned by the matching algorithm.(?'name'…)— Groups the subexpression as a singleAtom associated with the providedname. The result is captured and returned by the matching algorithm.(?P<name>…)— Groups the subexpression as a singleAtom associated with the providedname. The result is captured and returned by the matching algorithm.
See Also
Feature: Non-Capturing Groups
Main article |Reference |Back to top |Improve this section:1,2
ANon-capturing Group is a subexpression that can be treated as anAtom and can be repeated usingQuantifiers but cannot be referenced usingBackreferences. A Non-capturing Group is not captured by the matching algorithm.
Syntax
(?:…)— Groups the subexpression as a singleAtom.
See Also
Feature: Backreferences
Main article |Reference |Back to top |Improve this section:1,2
Backreferences allow a pattern to re-match a previously matched capture group12 either by number (n) or byname.
Syntax
\n— Wheren is an integer >= 1. Matches the same string as thecapture groupn.- NOTE: If then is > 9 it may be interpreted as an octal literal if there are less thanncapture groups in the pattern.
\gn— Wheren is an integer >= 1. Matches the same string as thecapture groupn.\g-n— Wheren is an integer >= 1. Matches thenth previouscapture group.\g+n— Wheren is an integer >= 1. Matches thenth nextcapture group.\g{n}— Wheren is an integer >= 1. Matches the same string as thecapture groupn.\g{-n}— Wheren is an integer >= 1. Matches thenth previouscapture group.\g{+n}— Wheren is an integer >= 1. Matches thenth nextcapture group.\g{name}— Matches thenamed capture group with the namename.\k<name>— Matches thenamed capture group with the namename.\k'name'— Matches thenamed capture group with the namename.(?P=name)— Matches thenamed capture group with the namename.
See Also
Feature: Comments
Main article |Reference |Back to top |Improve this section:1,2
AComment is a sequence of characters that is ignored by pattern matching and can be used to document a pattern.
Syntax
(?#…)— The entire expression is removed from the pattern. A comment may not contain other(or)characters.
See Also
Feature: Line Comments
Main article |Reference |Back to top |Improve this section:1,2
ALine Comment is a sequence of characters starting with# and ending with\n (or the end of the pattern) that is ignored by pattern matching and can be used to document a pattern.
Syntax
#…\n— The rest of the line starting from#is removed from the pattern. Only supported when thex(extended mode)RegExp flag is set.
See Also
Feature: Modifiers
Main article |Reference |Back to top |Improve this section:1,2
Modifiers allow you to change the currently activeRegExp flags within a subexpression.
Syntax
(?imsx-imsx)- Sets or unsets (using-) the specifiedRegExp flags starting at the current position until the next closing)or the end of the pattern. Example:(?-i)A(?i)B(?-i)CmatchesABC,AbC.(?imsx-imsx:…)- Sets or unsets (using-) the specifiedRegExp flags for the subexpression. Example:(?-i:A(?i:B)C)matchesABC,AbC.
See Also
Feature: Branch Reset
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
Feature: Lookahead
Main article |Reference |Back to top |Improve this section:1,2
ALookahead is a zero-width assertion that matches if the provided pattern would match the characters to the right of the current position.
Syntax
(?=…)— Positive Lookahead. Matches if the provided pattern would match but does not advance the current position.(?!…)— Negative Lookahead. Matches if the provided pattern would not match, but does not advance the current position.
See Also
Feature: Lookbehind
Main article |Reference |Back to top |Improve this section:1,2
ALookbehind is a zero-width assertion that matches if the provided pattern would match the characters to the left of the current position.
Syntax
(?<=…)— Positive Lookbehind. Matches if the provided pattern would match the preceding characters, but does not advance the current position. The pattern must have a fixed length (unboundedquantifiers are not permitted).(?<!…)— Negative Lookbehind. Matches if the provided pattern would not match the preceding characters, but does not advance the current position. The pattern must have a fixed length (unboundedquantifiers are not permitted).
See Also
Feature: Non-Backtracking Expressions
Main article |Reference |Back to top |Improve this section:1,2
ANon-Backtracking Expression is matched independent of neighboring patterns, and will not backtrack in the event of a failed match. This is often used to improve performance.
Syntax
(?>…)— Matches the provided pattern, but no backtracking is performed if the match fails.
Feature: Recursion
Main article |Reference |Back to top |Improve this section:1,2
ARecursive Expression provides a mechanism for re-evaluating acapture group inside of itself, to handle cases such as matching balanced parenthesis or brackets, etc.
Syntax
(?R)— Reevaluates the entire pattern starting at the current position.(?0)— Reevaluates the entire pattern starting at the current position.
Feature: Conditional Expressions
Main article |Reference |Back to top |Improve this section:1,2
AConditional Expression checks a condition and evaluates its first alternative if the condition istrue; otherwise, it evaluates its second alternative.
Syntax
(?(condition)yes-pattern|no-pattern)— Matchesyes-pattern ifcondition istrue; otherwise, matchesno-pattern.(?(condition)yes-pattern)— Matchesyes-pattern ifcondition istrue; otherwise, matches the empty string.
Conditions
The following conditions are supported:
(?(?=test-pattern)…)— Evaluates totrue if alookahead fortest-pattern matches; Otherwise, evaluates tofalse.(?(?!test-pattern)…)— Evaluates totrue if a negativelookahead fortest-pattern matches; Otherwise, evaluates tofalse.(?(n)…)— Evaluates totrue if thecapture group at offsetn was successfully matched; Otherwise, evaluates tofalse.(?(<name>)…)— Evaluates totrue if thenamed capture group with the namename was successfully matched; Otherwise, evaluates tofalse.(?('name')…)— Evaluates totrue if thenamed capture group with the namename was successfully matched; Otherwise, evaluates tofalse.(?(R)…)— Evaluates totrue if inside arecursive expression; Otherwise, evaluates tofalse.(?(Rn)…)— Evaluates totrue if inside arecursive expression for thecapture group at offsetn; Otherwise, evaluates tofalse.(?(R&name)…)— Evaluates totrue if inside arecursive expression for thenamed capture group with the namename; Otherwise, evaluates tofalse.(?(DEFINE)…)— Always evaluates tofalse. This allows you to defineSubroutines.
Feature: Subroutines
Main article |Reference |Back to top |Improve this section:1,2
ASubroutine is a pre-definedcapture group ornamed capture group that can be reused in multiple places within the pattern to re-evaluate the subexpression from the group.
Syntax
(?(DEFINE)…)— Defines a set of reusablecapture groups that can be referenced elsewhere in the pattern.(?n)— Wheren is an integer >= 1. Evaluates thecapture group whose offset isn.(?-n)— Wheren is an integer >= 1. Evaluates thecapture group whose offset is thenthcapture group declared to the left of the currentAtom. Example:(?-1)would revaluate the last declaredcapture group.(?+n)— Wheren is an integer >= 1. Evaluates thecapture group whose offset is thenthcapture group declared to the right of the currentAtom. Example:(?+1)would evaluate the next declaredcapture group.(?&name)— Evaluates thenamed capture group with the providedname.(?P>name)— Evaluates thenamed capture group with the providedname.
Example
(?(DEFINE) (?<Year>\d{4}|[+-]\d{5,}) (?<Month>0[1-9]|1[0-2]) (?<Day>0[1-9]|2[0-9]|3[01]))(?<Date>(?&Year)-(?&Month)-(?&Day)|(?&Year)(?&Month)(?&Day))Feature: Callouts
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.
Feature: Backtracking Control Verbs
Main article |Back to top |Improve this section:1,2
❌ This feature is not supported.