Regular Expression – Validate Gmail addresses

You did not tell which regex implementation you use. [a-z0-9] first character (\.?[a-z0-9]){5,} at least five following alphanumeric characters, maybe preceded by a dot (see @Daniel’s comment, copied from @Christopher’s answer) g(oogle)?mail gmail or googlemail (see @alroc’s answer) Probably you will want to use case-insensitive pattern matching, too. (/…/i in JavaScript.)

Difference between \w and \b regular expression meta characters

The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a “word boundary”. This match is zero-length. There are three different positions that qualify as word boundaries: Before the first character in the string, if the first character is a word character. After the last character in … Read more

Question marks in regular expressions

The key difference between ? and ?? concerns their laziness. ?? is lazy, ? is not. Let’s say you want to search for the word “car” in a body of text, but you don’t want to be restricted to just the singular “car”; you also want to match against the plural “cars”. Here’s an example sentence: I own three cars. Now, if I wanted … Read more

Regex for string contains?

Assuming regular PCRE-style regex flavors: If you want to check for it as a single, full word, it’s \bTest\b, with appropriate flags for case insensitivity if desired and delimiters for your programming language. \b represents a “word boundary”, that is, a point between characters where a word can be considered to start or end. For example, since spaces are … Read more

Regex optional group

You can easily simplify your regex to be this: I’m not sure whether the input string without the first group will have the underscore or not, but you can use the above regex if it’s the whole string. regex101 demo As you can see, the matched group 1 in the second match is empty and … Read more

Using the star sign in grep

The asterisk is just a repetition operator, but you need to tell it what you repeat. /*abc*/ matches a string containing ab and zero or more c’s (because the second * is on the c; the first is meaningless because there’s nothing for it to repeat). If you want to match anything, you need to say .* — the dot … Read more

Regular expression for exact match of a string

if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you: in perl the test for matching the password would be something like EDIT: bart kiers is right tho, why don’t you use a strcmp() for this? every language has it in its own way … Read more

Regular expression to match a word or its prefix

Square brackets are meant for character class, and you’re actually trying to match any one of: s, |, s (again), e, a, s (again), o and n. Use parentheses instead for grouping: or non-capturing group: Note: Non-capture groups tell the engine that it doesn’t need to store the match, while the other one (capturing group does). For small stuff, either works, for ‘heavy duty’ stuff, you … Read more

Searching for UUIDs in text with regex

I agree that by definition your regex does not miss any UUID. However it may be useful to note that if you are searching especially for Microsoft’s Globally Unique Identifiers (GUIDs), there are five equivalent string representations for a GUID:

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