Implementing Regular Expressions in TypeScript Types (Badly)
skalt.github.io
Implementing Regular Expressions in TypeScript Types (Badly)
1–10 of 13 posts
Re: Implementing Regular Expressions in TypeScript Types (Badly)
#2Re: Implementing Regular Expressions in TypeScript Types (Badly)
#3Having compile-time RegEx's would certainly fix some issues I've had with them in Python. As they are just buried in plain strings, there's no validation of their syntax until you hit the line of code that tried to use them only to discover that Python 3.12 has changed the syntax and what was once working is now broken. I'd love to see this validated at compile-time/load-time of any language to avoid those unexpected…
Re: Implementing Regular Expressions in TypeScript Types (Badly)
#4Having compile-time RegEx's would certainly fix some issues I've had with them in Python. As they are just buried in plain strings, there's no validation of their syntax until you hit the line of code that tried to use them only to discover that Python 3.12 has changed the syntax and what was once working is now broken. I'd love to see this validated at compile-time/load-time of any language to avoid those unexpected…
C# has compile-time regex, which are turned into fairly reasonable code doing the matching you can even inspect. The main goal isn't to have the syntax verified during compilation (technically it happens even during editing the code), but rather to reduce either dependencies on complex code at runtime, while still maintaining good performance by using the complex regex.
Re: Implementing Regular Expressions in TypeScript Types (Badly)
#5Having compile-time RegEx's would certainly fix some issues I've had with them in Python. As they are just buried in plain strings, there's no validation of their syntax until you hit the line of code that tried to use them only to discover that Python 3.12 has changed the syntax and what was once working is now broken. I'd love to see this validated at compile-time/load-time of any language to avoid those unexpected…
>>> re.compile(r'\w++')
re.error: multiple repeat at position 3
To use such a compiled pattern, you can call the method on this object instead of `re`. For example: >>> word = re.compile(r'\w+')
>>> word.findall('hello-there!')
['hello', 'there']Re: Implementing Regular Expressions in TypeScript Types (Badly)
#6Re: Implementing Regular Expressions in TypeScript Types (Badly)
#7Having compile-time RegEx's would certainly fix some issues I've had with them in Python. As they are just buried in plain strings, there's no validation of their syntax until you hit the line of code that tried to use them only to discover that Python 3.12 has changed the syntax and what was once working is now broken. I'd love to see this validated at compile-time/load-time of any language to avoid those unexpected…
If you need to detect syntax issues, you can use `re.compile()`. For example, before Python 3.11, you'll get an error: >>> re.compile(r'\w++') re.error: multiple repeat at position 3 To use such a compiled pattern, you can call the method on this object instead of `re`. For example: >>> word = re.compile(r'\w+') >>> word.findall('hello-there!') ['hello', 'there']
Re: Implementing Regular Expressions in TypeScript Types (Badly)
#8Re: Implementing Regular Expressions in TypeScript Types (Badly)
#9Re: Implementing Regular Expressions in TypeScript Types (Badly)
#10Nice! My version: https://github.com/desi-ivanov/ts-regexp