Regex: ignore case sensitivity

Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it: Check the documentation for your language/platform/tool to find how the matching modes are specified. If you want only part of the regex to be case insensitive (as my original answer presumed), then you … Read more

How can I validate an email address using a regular expression?

The fully RFC 822 compliant regex is inefficient and obscure because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use. One RFC 5322 compliant regex … Read more

Regex: ignore case sensitivity

Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it: Check the documentation for your language/platform/tool to find how the matching modes are specified. If you want only part of the regex to be case insensitive (as my original answer presumed), then you … Read more

Difference between \b and \B in regex

The confusion stems from your thinking \b matches spaces (probably because “b” suggests “blank”). \b matches the empty string at the beginning or end of a word. \B matches the empty string not at the beginning or end of a word. The key here is that “-” is not a part of a word. So … Read more

Regular expression to match a line that doesn’t contain a word

The notion that regex doesn’t support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds: The regex above will match any string, or line without a line break, not containing the (sub)string ‘hede’. As mentioned, this is not something regex is “good” at (or should do), but still, it … Read more

How can I validate an email address using a regular expression?

The fully RFC 822 compliant regex is inefficient and obscure because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use. One RFC … Read more