10 ms·
The literal matches are useful in an editor search context where most of the time you want to search for the literal string.
by cmovq 4y ago
The 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.