5 ms·
Is there a regular expression to detect a valid regular expression? (2008)
- dang 2y agoRelated: Is there a regular expression to detect a valid regular expression? - https://news.ycombinator.com/item?id=20909939 https://news.ycombinator.com/item?id=20909939 - Sept 2019 (219 comments)
- andy99 2y agoOther than the appealing symmetry of being able to use a language to parse that same language, this feels very similar to https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags https://stackoverflow.com/questions/1732348/regex-match-open... Edit: I just checked and sadly someone beat me to it in 2019: https://news.ycombinator.com/item?id=20910120 https://news.ycombinator.com/item?id=20910120
- bediger4000 2y agoThe user ID that asked the question looks to have last answered a question in 2016. I'm not sure what this means. Have we asked and answered all the good questions already?
- d5ve 2y agoDamian Conway's https://metacpan.org/pod/PPR https://metacpan.org/pod/PPR module defines a regex (in the commonly used sense) that can match perl source code - including perl regexes! Edit: "The PPR module provides a single regular expression that defines a set of independent subpatterns suitable for matching entire Perl documents, as well as a wide range of individual syntactic components of Perl (i.e. statements, expressions, control blocks, variables, etc.)"
- sshine 2y agoI answered a funny regex question once, “can strings that are base64 encoded twice be matched with a regex?” https://stackoverflow.com/questions/49650847/determine-if-string-is-base64-encoded-twice https://stackoverflow.com/questions/49650847/determine-if-st... The answer is yes, they’re regular. :-D
- bediger4000 2y agoThat's amazing. Thank you!
- verteu 2y agoTechnically, the set of strings containing balanced parentheses is not a regular language...
- wyldfire 2y agoOh man you've already got two problems? Maybe it's four now.
- willcipriano 2y agoWhat about a regular expression that detects regular expressions that detect valid regular expressions?
- a-dub 2y agoprotip: a language is not regular if you need counter(s) to parse it. protip 2: good regex implementations often have extensions that support counters.
- sargstuff 2y agosymantics vs. non-semantics. Perhaps examples/explainations of where regular expressions sit relative to grammars, grammar validation, syntax, and parsing might be helpful. [0][1][2][3][4] [0] : https://web.mit.edu/6.005/www/fa15/classes/17-regex-grammars/ https://web.mit.edu/6.005/www/fa15/classes/17-regex-grammars... [1] : https://peerj.com/preprints/1248.pdf https://peerj.com/preprints/1248.pdf [2] : https://www.cs.ox.ac.uk/ralf.hinze/WG2.8/28/slides/fritz-paper.pdf https://www.cs.ox.ac.uk/ralf.hinze/WG2.8/28/slides/fritz-pap... [3] : https://www.npmjs.com/package/regexp-tree https://www.npmjs.com/package/regexp-tree [4] : example bnf grammar for regular expressions : https://github.com/DmitrySoshnikov/regexp-tree/blob/master/src/parser/regexp.bnf https://github.com/DmitrySoshnikov/regexp-tree/blob/master/s...
- sargstuff 2y ago"regualr stuff" : https://www.geeksforgeeks.org/regular-expressions-regular-grammar-and-regular-languages/ https://www.geeksforgeeks.org/regular-expressions-regular-gr...