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

What is a Context Free Grammar?

A context free grammar is a grammar which satisfies certain properties. In computer science, grammars describe languages; specifically, they describe formal languages. A formal language is just a set (mathematical term for a collection of objects) of strings (sequences of symbols… very similar to the programming usage of the word “string”). A simple example of …

Read more

Using or ‘|’ in regex [duplicate]

It’s because you are trying to match against the entire string instead of the part to find. For example, this code will find that only a part of the string is conforming to the present regex: When you want to match an entire string and check if that string contains he|be|de use this regex .*(he|be|de).* . means …

Read more

OR condition in Regex

Try or add a positive lookahead if you don’t want to include the trailing space in the match When you have two alternatives where one is an extension of the other, put the longer one first, otherwise it will have no opportunity to be matched.