Skip to content

Global flag not respected on regex pattern #72

Closed
@CampbellMG

Description

@CampbellMG

If I utilise a regex with the global flag enabled, like this:

<ParsedText parse={[{pattern: /a/g, renderText: () => 'z'}]}> aaaa </ParsedText>

I would expect the output to be: zzzz

Whereas, I would expect this:

<ParsedText parse={[{pattern: /a/, renderText: () => 'z'}]}> aaaa </ParsedText>

to output: zaaa as the global flag is removed and is only matching the first instance.

At the moment the second example will output zzzz as the parser will continue matching the pattern against any remaining text.

While I understand there may be people depending on this behaviour is there any workaround to ensure only the first match is rendered?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions