Groups
Groups are a powerful tool of regular expressions. You can capture matches, join or summarize them.
To make things easier for you, think of groups as sub-queries. Everything in between a group could be a standalone expression which will later be combined.
Every group allows you to supply either a sub-query using parentheses, or just a literal string using quotes instead.
capture ... as
capture (condition) [as "name"]
To go beyond simply validating input, a capture group comes in handy. You can capture any condition and return it by the engine. This helps you to filter inputs and only get the parts you care about.
If you're trying to get more than one match, capture names are useful, too. This is completely optional, but
you can supply a name for a capture group using the as "name"
syntax.
Example query:
capture (anything once or more) as "first", literally " - ", capture "second part" as "second"
SRL Query is matching!
SRL Query is not matching.
The SRL Query contains an error:
Whoops... you may have found a bug.
Generated Regular Expression:
any of
any of (condition)
If you're not exactly sure which part of the condition will match, use any of
. Every
statement you supply in that sub-query, could be a match.
As you can see, you can feel free to nest multiple groups and even parentheses. If you would have removed the
parentheses around the digit once or more
, the expression would be invalid, since you can't
match either a digit, or "once or more".
Note: either of
is a synonym of any of
.
Example query:
capture (any of (literally "sample", (digit once or more)))
SRL Query is matching!
SRL Query is not matching.
The SRL Query contains an error:
Whoops... you may have found a bug.
Generated Regular Expression:
until
until (condition)
Sometimes you want to match or capture a specific expression until some other condition meets. This can be achieved using the until
group.
In the example below, we'll provide a string as a condition. However, this would work as well using a more complex expression, just like above.
Example query:
begin with capture (anything once or more) until "m"