Regex doesn't detect symbol [duplicate] - regex

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 7 years ago.
User input might look like:
* symbol with 1 character limit (no other symbols than *)
or
A-E, a-e letters with 1 character limit
Following data is valid examples: *; a; A; e; D
I don't understand why ^[A-Ea-e]{1}\*?$ doesn't work?
https://regex101.com/r/iG7wG6/1

You just need a character class:
^[A-Ea-e*]$
RegEx Demo
You regex is only allowing an optional * after A-E or a-e but never * alone.

Try using regex groups:
^([A-Ea-e]|\*)$
You want to have two different alternatives:
one of the A-E or a-e characters, OR
the * character.

Related

Regex: how to find two letters that are repeating at least 3 number of times? [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
For example, I would like to find ty in:
erytypotym5ty
etytyty
koetymitywty
or il in:
keililmil
ilwrilltyil5ile
^.*(\w{2}).*\1.*\1.*$.
The two letters (also digits and _; you could replace \w with [a-zA-Z], if you don't want them) will be in group 1.
https://regex101.com/r/11Oq70/1

Remove last character from regex match [duplicate]

This question already has answers here:
How can I match "anything up until this sequence of characters" in a regular expression?
(15 answers)
Closed 3 years ago.
I have strings that are concatenations of airline codes/flightnumbers, separated with ;. The airline code and flight number are either separated by a space or -. So some examples are:
AA-1234;UA 243;EK 23;
9W 23;B6-134
Now I want to grab the airline codes from this.
I came up with the following regex: [a-zA-Z0-9]{2}[ -]. This works to grab the airline codes but also includes the airlinecode-flightnumber separator. How would I adjust my regex to not include this?
[a-zA-Z0-9]{2}(?=[ -])
See it in action here

Regex for custom email validation [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 4 years ago.
Trying to create custom email validation for below rules
The local part can be up to 64 characters in length and consist of any combination of alphabetic characters, digits, or any of the following special characters:
! # $ % & ‘ * + – / = ? ^ _ ` . { | } ~
The period character (".") is valid for the local part subject to the following restrictions: A. it is not the first or last character
B. two or more consecutive periods
top level domains cannot be all numeric
hyphens cannot be the first or last character
^([a-zA-Z0-9!#\$%&‘*+/\=\?\^_'`}{\|~-][.]?)#[a-zA-Z0-9]+(?:(.)\0?(?!\1))[a-zA-Z0-9-]*[a-zA-Z0-9]+(.[a-zA-Z0-9]{2,63})+$
First part (before # )is good but unable to place
two or more consecutive periods
hyphens cannot be the first or last character
for example
leela.test#te-st.gm-ail.com(correct)
leela.test#te-st..gm-ail.com(incorrect)
leela.test#.te-st.gm-ail.com(incorrect)
leela.test#-te-st.gm-ail-.com(incorrect)
leela.test#.te-st.gm-ail-.com(incorrect)
leela.test#test.gmail.com(correct)
leela#gmail.com(correct)
leela#test.gm-ail.com(correct)
Please help.
[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*\#[a-zA-Z0-9]+\-[A-Za-z0-9]+\.[a-zA-Z0-9]+\-[A-Za-z0-9]+\.com

difference between 2 regex strings [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
What is the difference in what these 2 are doing? Thx
var m = document.referrer.match(/\&cd=([\d]*)/);
and
var m = document.referrer.match(/cd=(.*?)&/);
Which one is more efficient and effective?
/\&cd=([\d]*)/ - matches any string starting with an "&cd=" followed by any zero or more decimal digits. The first capture group is the decimal digits.
/cd=(.*)&/ - matches any string starting with an "cd=" followed by zero or more characters up to and including the first "&". The first capture group is all characters between "cd=" and "&".
They are similar, but not equivalent. Which one you should use depends on your exact needs. Judging from your comment, it sounds like you want to use:
var m = document.referrer.match(/[?&]cd=(\d+)/);

regex: match at least one character from set [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
I have a character set {x, y, z} and I want to check if some string contains at least one character from this set.
For example:
abxyz - valid
zabc1 - valid
abc4e - not valid
/.*[xyz].*/ should do the trick
Try this regex:
.*[x-z].*
This will only match lines that include [x-z] at least once.
Example