Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 … Read more

Matching a space in regex

If you’re looking for a space, that would be ” ” (one space). If you’re looking for one or more, it’s ” *” (that’s two spaces and an asterisk) or ” +” (one space and a plus). If you’re looking for common spacing, use “[ X]” or “[ X][ X]*” or “[ X]+” where X … 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

Javascript split regex question

You need the put the characters you wish to split on in a character class, which tells the regular expression engine “any of these characters is a match”. For your purposes, this would look like: Although dashes have special meaning in character classes as a range specifier (ie [a-z] means the same as [abcdefghijklmnopqrstuvwxyz]), if you put it as … Read more

How can I exclude one word with grep?

You can do it using -v (for –invert-match) option of grep as: grep -v “unwanted_word” file will filter the lines that have the unwanted_word and grep XXXXXXXX will list only lines with pattern XXXXXXXX. EDIT: From your comment it looks like you want to list all lines without the unwanted_word. In that case all you need is:

What do ++ and *+ mean?

++ From What is double plus in regular expressions? That’s a Possessive Quantifier. It basically means that if the regex engine fails matching later, it will not go back and try to undo the matches it made here. In most cases, it allows the engine to fail much faster, and can give you some control … Read more

Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 combinations of lookarounds with 2 axes: lookbehind / lookahead : … Read more

What does \’.- mean in a Regular Expression

The character class is the entire expression [A-Z \’.-], meaning any of A–Z, space, single quote, period, or hyphen. The \ is needed to protect the single quote, since it’s also being used as the string quote. This charclass must be repeated 2 to 20 times, and because of the leading ^ and trailing $ … Read more

Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 combinations of lookarounds with 2 axes: lookbehind / lookahead : … Read more