Skip to content

Request: (?(DEFINE)...) #152

@mrabarnett

Description

@mrabarnett

Original report by boolbag NA (Bitbucket: boolbag, GitHub: boolbag).


Hi again Matthew,

This is the second in a series of posts to present a case for three features.
In this post, I'll focus on (?(DEFINE)...)

When crafting long expressions with repeated components, I find the (?(DEFINE)...) syntax immensely valuable. It is the key to writing modular regex. Some time ago I presented an example to show the value of such a modular regex here.

(?(DEFINE)...) allows you to drop short names in the pattern. These names expand to large sub-expressions. When sub-expressions are repeated in multiple places in the pattern, this lets you keep your sanity, because you don't have to change the pattern in multiple places.

I came up with a workaround that I explained here some time ago. Nevertheless, for compatibility with PCRE and Perl when translating large expressions, it would be wonderful to have the same (?(DEFINE)...) syntax in regex.

Thanks in advance for considering it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions