5 ms·
I really dislike that patterns using * wildcard required using the letters beforehand. The game requires A* to match a row with zero or more A's, but this is a
by toastedzergling 12y ago
I really dislike that patterns using * wildcard required using the letters beforehand. The game requires A* to match a row with zero or more A's, but this is absolutely incorrect, as A* will gladly match ANY string, like QQQQ.
- mgraczyk 12y agoThat isn't how the Kleene star works. A* is "the set of all strings over the alphabet {A}, including the empty string ε." "QQQQ" is not a string over the alphabet {A} because it contains the symbol 'Q', which is not in {A}.
- toastedzergling 12y agoI have no idea what you're talking about. My point is more pragmatic the regex /A/ will match the string "QQQQ" and this tool doesn't take that into account. E.g., I type this into my javascript console: /A*/.test('QQQQ'); > true Showing that yes, /A/ does match 'QQQQ'
- takeda 12y agoActually this is wrong, when you use A* in vim for example you're not looking exactly for A* but for substring containing an A* since this also matches "" programs like vim will match anything. Just because these tools use regex this way doesn't mean that's how regex really works.
- mgraczyk 12y agoNo, it doesn't. It matches the empty string at the beginning of 'QQQQ', not the Qs themselves: /A*/.exec('QQQQ') [""] When computer scientists discuss what a regular express does and does not "match", they are saying that strings which are "matched" by a regex are those strings which are members of the regular language defined by the regex. QQQQ is not a string in the language defined by /A* /, so /A* / does not match QQQQ. If we look at things your way, we would have to say that the regex /A/ matches "AQQQQ". It does not. It matches "A".
- eridius 12y agoThat's not an issue with A*. Every regex here has an implied anchor to the start and end of the string.
- toastedzergling 12y agoFair enough, but implied anchors are not part of the regex standard
- bmm6o 12y ago* is not a wildcard, it indicates that the preceding token occurs zero or more times.
- toastedzergling 12y agoYes, that's exactly my point. By occuring zero times, it means the preceeding token is irrelevant, and will match any arbitrary string.
- wodenokoto 12y agoSo you are saying that // will match any arbitrary string?
- ddebernardy 12y agoAs I saw, the regexps are all implicitly anchored. When you read `A`, you need to be thinking `\AA\Z`.