4 ms·
Regex
by ljlolel 1y ago
Regex
- AnimalMuppet 1y agoFair point, though I learned regexes a long time ago, so that they weren't on my "problems that I can solve with new syntax" list, but instead on the "syntax that's already there" list.
- miki123211 1y agoTBH, I feel like regexes would be much easier to understand in a more literate form with standard syntax. Something like: user_part = re.repeat(re.alnum | re.chars(".-_+")) domain_segment = re.repeat(re.alnum) domain = re.list(domain_segment,separator=".",minimum=2) email_address = user_part + "@" + domain Where, in a real program, `domain` would be defined in a "standard library of constructions" that you can just import and re-use in more complicated regexes. Something like this can be implemented in any language with operator overloading, no DSL required. Without operator overloading, the syntax would be a bit more awkward, but still nicer than the current regexp madness.
- ChadNauseam 1y agoI don't quite understand where regex gets its reputation from. I think that once you remember the meaning of the operators, it's not too bad. (And the concise syntax is actually very helpful.) I get that the meaning of the operators is not clear unless you're already familiar with regex, but neither is the meaning of !, ?, %, &, |, ^, ~, &&, ||, <<, >>, *, //, &, ++ (prefix), ++ (postfix), and so on. You learn these because you need them once, and then they're burned into your mind forever. Regex was similar for me.
- troupo 1y agoAlso, regexps are just that: regular. You can mostly read them from left to right decoding each symbol at a time.
- spinningarrow 1y agoI think regex gets some of its hate from people writing painfully complex matchers. 99% of my day to day regex use is simpler string searches on the command line or in my editor. I’m really happy I took the time to learn the syntax (spent about a week on it around 15 years ago) because now it doesn’t get in my way.
- jolt42 1y agoThe limitation with regex is that's it's context free, whereas a regular grammar is simpler and more powerful IMO.
- miki123211 1y agoRegex syntax helps you understand what a regex does, not necessarily why it does it. You can't decompose it into parts, you can't give those parts human-friendly names, you can't re-use parts in other regexes, you can't (easily) write functions that return or manipulate regexes (like that "list with separator" function shown above).
- librasteve 1y agorecommend you check out raku Grammars … https://docs.raku.org/language/grammars https://docs.raku.org/language/grammars
- draegtun 1y agoOr in Red's case, Parse - https://www.red-lang.org/2013/11/041-introducing-parse.html https://www.red-lang.org/2013/11/041-introducing-parse.html
- binary132 1y agoThere’s really nothing about this that couldn’t be expressed just as clearly in a more general API though, even in C, IMO. Building it into the syntax is a little weird to me.
- draegtun 1y agoOr in Rebol/Red it's Parse, a dialect (DSL) that comes with the language - https://www.rebol.com/docs/core23/rebolcore-15.html https://www.rebol.com/docs/core23/rebolcore-15.html
- canadianfella 1y ago[dead]