5 ms·
It's probably better than regular expressions. However, is it enough better that it's worth learning yet another syntax? Well, maybe. What I REALLY like about
by vintermann 4y ago
It's probably better than regular expressions. However, is it enough better that it's worth learning yet another syntax?
Well, maybe. What I REALLY like about this one, is that it fully reverses the quoting/escaping assumptions. The default assumption of old regexes that symbols should by default match themselves, I think is regexes' million dollar mistake. The literal matches are the least interesting part of regexes. If you reach for regexes, it's because you want something more complex than literal matches, and the syntax should be about taming that complexity. Even the Unix world sort of conceded that, in reversing the quoting assumption for ?, +, (), [] and | in egrep. The mistake was in stopping there.
I will take a good look at this. I hope they provide good justifications for their choices.
- coffeeblack 4y agoOn first glance, I didn’t see anything better, tbh.
- SCLeo 4y agoI think the number ranges functionality is pretty handy. In addition, I also like how it supports comments. (However, I do think if the regex grows to needing comments, it is probably too complex.)
- cmovq 4y agoThe literal matches are useful in an editor search context where most of the time you want to search for the literal string.
- chongli 4y agoYes and editor search is one of the few reasons to use regex these days. If you're writing something more permanent then you should use a real parser library!
- nlitened 4y agoAdd a new library dependency when built-in one-liner regex does just fine? I don’t think that’s a good idea by any measure. Also, learning regex syntax has much better ROI and is a much more transferable skill, than learning a specific parser library’s syntax and bugs. Just invest 30 minutes once in your life into learning basic regex, for Christ’s sake, it’s not that hard!
- nerdponx 4y agoOr use a 21st-century language that has a parser framework in the standard library ;) Of course you can't always use a 3rd-party library, but IMO it should be your default choice without additional constraints. Much like how a memory-safe garbage-collected language should be your default choice for most things.
- vintermann 4y agoFor search, true, you usually want literals. But for search and replace, you usually want regular expressions. It's a quick toggle. Or you can just wrap your literal in quotes.
- gpvos 4y agoPerl regex syntax does what you describe, and has done so since the 1990s. Only alphanumeric characters are guaranteed to match themselves, and the others have a special meaning unless escaped. Some nonalphanumeric characters don't have a special meaning and you can use them either with or without a backslash, but the man page has always warned that it's safer to escape them anyway.
- nerdponx 4y agoVim regex is even nicer in this regard because it has four different modes, ranging from "everything is a literal except \\" to "everything is an operator except 0-9A-Za-z". This makes it great for searching code with symbols in it, because you can set it to the "very no-magic" mode and type your symbols as-is, or switch to "very magic" mode for a pattern that uses a lot of control flow. Still, regex remains a great choice for one-off interactive purposes because it's concise, but for an application something with better composability and a clearer delineation between operators and literals is beneficial. You don't replace all uses of regex with Pomsky, you replace it specifically in "apps" where the pattern is part of the code.
- g0xA52A2A 4y agoAnnoyingly you can’t set “very magic” only “magic”. So I have written some vimscript to try and ensure when I start a pattern it starts with “\v” though I’d hesitate to call it robust.
- gpvos 4y agoI recently discovered this. It sounds horrible to have four different modes (unless they are exact emulations of existing other implementations, that would be a useful feature).