3 ms·
How else would you write that you want to match all strings that don't contain string X? If you were matching at a specific position, you should use a negative
by enricozb 6y ago
How else would you write that you want to match all strings that don't contain string X? If you were matching at a specific position, you should use a negative lookahead (?!xyz), but I think in some cases you might need the mess above.
- recursive 6y agoI can't imagine a case where the mess would be useful at all. Negative lookahead is the only way I can imagine this being possibly useful. I.E. "Give me a string that's not trump and has a vowel in it". Given "trunk", that mess above would match all of "trun". Would good is matching a prefix going to do ever?
- kleiba 6y agoIf you concede that the standard regex construct [^x] is a useful construct at all -- match any character except x -- why would should such a negative match be restricted to only a single character? Why not also allow for, say, match anything except the following _two_ characters in a row?
- recursive 6y ago> Why not also allow for, say, match anything except the following _two_ characters in a row? That part could be useful, but not when the pattern matches a seemingly random number of characters in the process. [^x] is more predictable. It matches a single character, or not at all.
- kleiba 6y agoThat part could be useful [...] Well, then by application of your name, it should be useful for any number of characters. They're not random -- they spell out a word you would like not to match. I'm not sure what you mean with "predictable". Are you referring to readability of the expression? I totally give you that... which kinda was my whole argument to begin with.
- recursive 6y agoAny substring of a shorter length than the no-no word spells out a word which doesn't match it. My opening statement was that I can't see a practical use for it. I still can't. Maybe one exists. But I don't think we're getting anywhere.