Live data from Hacker News

ArkRegex: A drop in replacement for new RegExp() with types

arktype.io

1–7 of 7 posts

Re: ArkRegex: A drop in replacement for new RegExp() with types

#4
post #2

Sure, now make it work without having to type "\\w"

Yes, there are limits on what string literals can precisely represent, but we've tried to be pragmatic about trade offs around clarity, concision and performance.

Subexpressions like `\\w` or `[a-Z]` would just be inferred as `${string}`, but that doesn't mean the inference won't be useful. For example:

expression: regex("^\\w+@\\w+\\.\\w+$") type: Regex

Re: ArkRegex: A drop in replacement for new RegExp() with types

#5
post #2

Sure, now make it work without having to type "\\w"

Yes, there are limits on what string literals can precisely represent, but we've tried to be pragmatic about trade offs around clarity, concision and performance. Subexpressions like `\\w` or `[a-Z]` would just be inferred as `${string}`, but that doesn't mean the inference won't be useful. For example: expression: regex("^\\w+@\\w+\\.\\w+$") type: Regex

Can't you use tagged literals to do something similar?

Re: ArkRegex: A drop in replacement for new RegExp() with types

#6
post #5

Earlier quoted context omitted.

Yes, there are limits on what string literals can precisely represent, but we've tried to be pragmatic about trade offs around clarity, concision and performance. Subexpressions like `\\w` or `[a-Z]` would just be inferred as `${string}`, but that doesn't mean the inference won't be useful. For example: expression: regex("^\\w+@\\w+\\.\\w+$") type: Regex

Can't you use tagged literals to do something similar?

Not sure exactly what you mean by "something similar".

Re: ArkRegex: A drop in replacement for new RegExp() with types

#7
post #5

Earlier quoted context omitted.

Can't you use tagged literals to do something similar?

Not sure exactly what you mean by "something similar".

The issue is not being able to type actual regexes: /\w+[a-z]$/ becomes something different when enclosed in double quotes.