Skip to content

xregexp-like regexp/tag.ts #3421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wojpawlik opened this issue Jun 3, 2023 · 1 comment
Open

xregexp-like regexp/tag.ts #3421

wojpawlik opened this issue Jun 3, 2023 · 1 comment

Comments

@wojpawlik
Copy link

wojpawlik commented Jun 3, 2023

Small utility for combining regular expressions and strings, without worrying about escaping (#3330).

See https://xregexp.com/api/#tag and https://github.com./fromdeno/deno2node/blob/main/src/util/regexp.ts

@wojpawlik wojpawlik changed the title xregexp-like regexp/tag.ts and regexp/union.ts xregexp-like regexp/tag.ts Jun 3, 2023
@jeff-hykin
Copy link
Contributor

I made a little tool like this, and I have thought about creating a PR for it. I tried to do the flags a bit more elegantly

import { regex } from "https://deno.land/x/[email protected]/string.js"
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"

const pattern = regex`(not escaped) ${"(escaped)"} ${/(not escaped)/}`.gi
assertEquals(pattern, /(not escaped) \(escaped\) (?:(not escaped))/gi )

const pattern = regex`a`.ig
assertEquals(pattern, /a/gi)

If this looks good I'll clean it up with some jsdoc and type annotations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants