Regex for “AND NOT” operation

I’m looking for a general regex construct to match everything in pattern x EXCEPT matches to pattern y. This is hard to explain both completely and concisely…see Material Nonimplication for a formal definition. For example, match any word character (\w) EXCEPT ‘p’. Note I’m subtracting a small set (the letter ‘p’) from a larger set … Read more

What is the difference between square brackets and parentheses in a regex?

These regexes are equivalent (for matching purposes): /^(7|8|9)\d{9}$/ /^[789]\d{9}$/ /^[7-9]\d{9}$/ The explanation: (a|b|c) is a regex “OR” and means “a or b or c”, although the presence of brackets, necessary for the OR, also captures the digit. To be strictly equivalent, you would code (?:7|8|9) to make it a non capturing group. [abc] is a … Read more

Regular Expressions- Match Anything

How do I make an expression to match absolutely anything (including whitespaces)?Example: Regex: I bought _____ sheep. Matches: I bought sheep. I bought a sheep. I bought five sheep. I tried using (.*), but that doesn’t seem to be working.