2 ms·
I get the suspicion that the writer doesn't understand the ?, * and + operators...
by steffann 9y ago
I get the suspicion that the writer doesn't understand the ?, * and + operators...
- posterboy 9y agoa correction would be helpful. /x?/ one or none x /x+/ one or more x /x*/ none or more x with variable operators it's more complicated. In /.+/ the operator is repeated, not the first match as with /(.)\1*/ Also, there are extensions in various implementations that are not in fact a regular, so no finite automata.
- yorwba 9y agoThere is a problem here in that different regex libraries have different semantics for these. I checked the manual for PCRE (man pcrepattern), and it says that ? has both the meaning of {0,1} (zero or one repetition), as well as turning * and + into non-greedy variants if directly following them. Similarly, + usually has the meaning of {1,} (at least once) but can also quantify * and + to prevent backtracking. For an engine whose semantics differ from PCRE, non-greedy matching or backtracking might not even make sense, if the matching is implemented differently (e.g. using finite automata that don't backtrack).