Skip to content

[Question] How to match a string at start and end of token without capturing groups #170

@inferrinizzard

Description

@inferrinizzard

I am converting my custom tokenizer to moo and ran into a problem case:

// a pattern that used to look like this:
'(?<tag>\\$\\w*\\$)[\\s\\S]*?(?:\\k<tag>|$)'
// as regex literal:
/(?<tag>\$\w*\$)[\s\S]*?(?:\k<tag>|$)/

This pattern tries to match Postgres $$ strings, such as:

-- standard && string
$$lorem ipsum dolor$$
-- custom $$ string with tag (fails here)
$example$this example string fails$example$

The pattern normally works by backreferencing the captured tag between the first dollar signs to check if the second pair of dollar signs has the same tag but this breaks without the use of capturing group when lexing with moo.

Any suggestions on how to workaround this limitation ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions