Live data from Hacker News

Regular expressions that work “everywhere”

johndcook.com

21–30 of 51 posts

Re: Regular expressions that work “everywhere”

#22
Emacs in particular I suffer so much from basically guessing what needs to be escaped or not. I know `rx` exists[0] as an alternative but it's not really fun to use.

Even beyond the regex syntax itself, you often also start running into encoding problems when trying to actually use them. Typing the regex in a shell? Make sure to esacpe stuff properly. Regex in Python? Make sure it's a raw string. Etc etc etc

It's a modern miracle we're at least within rhyming distance of how to write regexes in most tools.

[0]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx...

Re: Regular expressions that work “everywhere”

#24

2 RegExp problems: 1. You can not compose a bigger regexp out of smaller ones 2. A regexp can not "call" other regexps

To do regex matching efficiently, you need to compile the pattern before using it. That'd exclude dynamically "calling" other regex patterns. But bigger regex pattern strings can be composed from smaller regex pattern strings. You'd just need to do the composition before the compilation.

Re: Regular expressions that work “everywhere”

#25
post #11

Earlier quoted context omitted.

Why? Of course it means the dialect that is most directly supported by that language (by builtins or the standard library). And why should they have to consider other dialects? They aren't reading regexes from user input (or they'd be a lot more concerned about sanitization, catastrophic backtracking etc.), and their fellow developers all grok the conventions.

Because I don't know what language your program is even written in! Why should I know or care that you chose, e.g. TypeScript, when I'm trying to use or configure your program and don't know how to spell this or that regex concept?

[deleted]

Re: Regular expressions that work “everywhere”

#26

It drives me nuts when a developer documents something or other as being a "regex" but doesn't mention which dialect of regulation expression he's talking about. This habit is particularly common in the Rust, JavaScript, and Python communities, which seem to forget that their language's regular expression language isn't universal.

Same applies to “Markdown”.

Re: Regular expressions that work “everywhere”

#27

2 RegExp problems: 1. You can not compose a bigger regexp out of smaller ones 2. A regexp can not "call" other regexps

To do regex matching efficiently, you need to compile the pattern before using it. That'd exclude dynamically "calling" other regex patterns. But bigger regex pattern strings can be composed from smaller regex pattern strings. You'd just need to do the composition before the compilation.

Also define blocks if all someone wants is to break the pattern up to make it more readable.

Re: Regular expressions that work “everywhere”

#29
post #22

Emacs in particular I suffer so much from basically guessing what needs to be escaped or not. I know `rx` exists[0] as an alternative but it's not really fun to use. Even beyond the regex syntax itself, you often also start running into encoding problems when trying to actually use them. Typing the regex in a shell? Make sure to esacpe stuff properly. Regex in Python? Make sure it's a raw string. Etc etc etc It's a m…

Grasping at straws, it's kinda convenient that ( and ) match literally if the text being searched is Elisp code!

Re: Regular expressions that work “everywhere”

#30

2 RegExp problems: 1. You can not compose a bigger regexp out of smaller ones 2. A regexp can not "call" other regexps

Swift has a RegexBuilder[1][2] interface, in addition to the usual string-ey interface that allows composition.

[1]: https://github.com/swiftlang/swift-evolution/blob/main/propo...

[2]: https://developer.apple.com/documentation/regexbuilder

Post reply on HN