Inline Regex
Inline regexes allow you to embed regular expressions in Pomsky.
Syntax
Section titled “Syntax”let InlineRegex = 'regex' String;
Example
Section titled “Example”regex '(?2)' # subroutineregex '[\w--[\p{Latin}]]' # character set subtraction
Support
Section titled “Support”Inline regexes are supported in all flavors.
Support for inline regexes is gated by the regexes
feature. Specify features with the
--allowed-features
option.
Behavior
Section titled “Behavior”Inline regexes can do anything the targeted regex engine supports. However, inline regexes may not be as portable, because different regex engines use slightly different syntax for some features.
Compilation
Section titled “Compilation”The string content is emitted by the compiler verbatim. If the expression is repeated, it is wrapped in a non-capturing group. Pomsky also adds a non-capturing group if the inline regex is surrounded by parentheses. For example:
Pomsky | Compiled regex |
---|---|
regex 'a|b' | a|b |
regex 'a|b'+ | (?:a|b)+ |
regex 'a|b' 'c' | a|bc |
(regex 'a|b') 'c' | (?:a|b)c |
This is the only situation where parentheses affect the compiled regex, even though they do not affect precedence in the Pomsky expression.
Issues
Section titled “Issues”Pomsky doesn’t know when the inline regex needs to be wrapped in a non-capturing group. No group is added when multiple expressions are concatenated, which may be incorrect if the inline regex is an alternation.
History
Section titled “History”Initial implementation in Pomsky 0.8