2 ms·
I wish one of those regex libraries that replaces the regex symbols with human readable words would become standard. Or they don't work well? Regex is one of t
by seanwilson 9mo ago
I wish one of those regex libraries that replaces the regex symbols with human readable words would become standard. Or they don't work well?
Regex is one of those things where I have to look up to remind myself what the symbols are, and by the time I need this info again I've forgotten it all.
I can't think of anywhere else in general programming where we have something so terse and symbol heavy.
- db48x 9mo agoIt’s been done. Emacs, for example, has rx notation. From the manual: 35.3.3 The ‘rx’ Structured Regexp Notation ------------------------------------------ As an alternative to the string-based syntax, Emacs provides the structured ‘rx’ notation based on Lisp S-expressions. This notation is usually easier to read, write and maintain than regexp strings, and can be indented and commented freely. It requires a conversion into string form since that is what regexp functions expect, but that conversion typically takes place during byte-compilation rather than when the Lisp code using the regexp is run. Here is an ‘rx’ regexp(1) that matches a block comment in the C programming language: (rx "/*" ; Initial /* (zero-or-more (or (not "*") ; Either non-*, (seq "*" ; or * followed by (not "/")))) ; non-/ (one-or-more "*") ; At least one star, "/") ; and the final / or, using shorter synonyms and written more compactly, (rx "/*" (* (| (not "*") (: "*" (not "/")))) (+ "*") "/") In conventional string syntax, it would be written "/\\*\\(?:[^*]\\|\\*[^/]\\)*\\*+/" Of course, it does have one disadvantage. As the manual says: The ‘rx’ notation is mainly useful in Lisp code; it cannot be used in most interactive situations where a regexp is requested, such as when running ‘query-replace-regexp’ or in variable customization. Raku also has advanced the state of the art considerably.