Skip to content

Suggestion to use raw template literals for parity with native syntax #13

@webstrand

Description

@webstrand

In your readme example

const groups2 = typedRegExp('^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$', 'g').exec('2000-10-24')!.groups;

the complicated and error-prone escaping can be made simpler by using String.raw (or the equivalent TemplateStringsArray#raw

const groups2 = typedRegExp(String.raw`^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$`, 'g').exec('2000-10-24')!.groups;

allowing you to keep the same syntax as in the native regex, making it easy to transform from one form to the other.

You could adapt an api like typedRegExp`^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$`.g.exec("2000-10-24")!.groups to make it seamless. I haven't thought enough about it to decide if that's a good idea or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedWaiting on external input or dependency before progress can continue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions