3 ms·
By using this “builder” syntax you gain: • not having to distinguish special characters in the pattern being matched from special characters part of regex synt
by TazeTSchnitzel 6y ago
By using this “builder” syntax you gain:
• not having to distinguish special characters in the pattern being matched from special characters part of regex syntax
• no ambiguity as to whether something is a digraph or not
• no escaping hell
• unambiguous human-readable names for all the regex features used
• the ability to use whitespace to clearly separate different parts of the regex
• the ability to comment parts of the regex
It sounds great to me. Have you ever tried making a regex matching something with backslashes in it, and then you have to put that regex inside a string literal? Have you ever had to switch between different regex environments and not known which symbols require escaping, or what is the correct way to write something in a particular environment? I've had all these problems.
- TimTheTinker 6y agoMany of those gains can be had by using first-class and more full-featured regexes, like those that that are available in other languages (Ruby, Perl): - escaping hell isn't that much of a problem, since you're only ever escaping something once (not like a regex in a string) - several languages support separating regexes across several lines - regex commenting (including named groups) is a standard feature in many languages, and that's besides using first-class comments across multiple lines I think you do have a point about digraphs (or homographs), but unless I misunderstand, those would be a problem whether or not the character(s) are part of a string vs. a first-class regex. As for unambiguous human-readable names for regex features used, tools like this (https://regexr.com/ https://regexr.com/) are available and very effective. I might prefer Java Verbal Expressions over java.util.regex, but to me that's more of a knock on Java and its lack of proper, first-class regexes than anything else.