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
Related
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
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
This question already has answers here:
A regex to match a substring that isn't followed by a certain other substring
(5 answers)
Closed 3 years ago.
How to mark xy if the next symbol is not y?
I have four strings:
1. zxyy
2. zxyz
3. zxy
4. xy
The epxression should mark strings 2-4.
This regex marks the 2-nd string only:
([x][y])(?=[^y])
Thanx.
The regex recommended by Aaron works as I wished:
xy(?!y)
It marks 2. zxyz 3. zxy 4. xy, but not 1. zxyy.
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.
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+)/);