Escaping Parentheses in Regex

If you want to match one of a set of character, it’s best to use a character class. And within such a class, most escaping rules don’t apply. So to match a dot, comma, slash or closing parenthesis, you can use

Regular expression that matches valid IPv6 addresses

I’m having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with :: or leading zeros omitted from each byte pair). Can someone suggest a regular expression that would fulfill the requirement? I’m considering expanding each byte pair and matching the result with a simpler regex.

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.

Regular expression to limit number of characters to 10

I am trying to write a regular expression that will only allow lowercase letters and up to 10 characters. What I have so far looks like this: This does not work or compile. I had a working one that would just allow lowercase letters which was this: But I need to limit the number of … Read more

Regular expression to remove HTML tags from a string

You should not attempt to parse HTML with regex. HTML is not a regular language, so any regex you come up with will likely fail on some esoteric edge case. Please refer to the seminal answer to this question for specifics. While mostly formatted as a joke, it makes a very good point. The following examples are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)