3 ms·
If I understand what OP means by "and", it doesn't mean "(abc OR def) AND (123 OR 456)" — it means "(abc OR def) FOLLOWED BY (123 OR 456)". Let's look at anothe
by chc 10y ago
If I understand what OP means by "and", it doesn't mean "(abc OR def) AND (123 OR 456)" — it means "(abc OR def) FOLLOWED BY (123 OR 456)". Let's look at another example, with a hypothetical & operator:
/(\D\S)+/
/(\D|\S)+/
/(\D&\S)+/
If you look at the string "b5 ", the first regex matches "b5", the second regex matches the whole string because all of the characters are either not a number or not whitespace, and the third regex only matches "b", because that's the only character that is both not a number and not whitespace.
- rnovak 10y ago\D is a subset of \S, so the \S accomplishes nothing (said another way, there is no character that matches \D that doesn't also match \S). Secondly, there are very few intersecting character classes (sets) that I'm aware of, and in all cases, you could achieve the desired result more clearly in other ways. Said another way: "AND" would just make regexes even harder to understand/approach, and that is almost always undesirable.
- chc 10y agoI was just trying to illustrate how the logic of AND differs from what was shown above, not give a useful example. A more practical example might be something like /(10|22)(.*crab.*&.*apple.*)90/ in order to only match strings where the content between the numeric codes matches both "crab" and "apple" in any order. To be clear, I don't know that it's useful enough to warrant inclusion in a regex engine. I'm just trying to provide a useful illustration.