Regex for any name [duplicate] - regex

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 5 years ago.
I want regex with at least 2 characters start with any alphabet or any digit not matters.But It can accept - and _ .
Ex : ABD , Abc_123 , 12, A-_ , A1 etc.

(Updated)
(?=[-\w]{2}).*
Online test, https://regex101.com/r/JcUaBz/2

This should do the trick:
[\w-]{2,}
But, if you want to ignore words that have special characters, you can use this:
(?<=\s|^)([\w-]{2,})(?=\s+|$)

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 this {{mike}} {{michael}} {{jordan}} [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
My String is -> {{mike}} {{michael}} {{jordan}}
Give me result like this
group 1 -> mike
group 2 -> michael
group 3 -> jordan
In general you can go for this
\{\{(\w+)\}\}
It captures all the characters inside the double braces (without spaces, if you need space you can use [\w\s]* inside the braces)

How to find a part of string with regex? [duplicate]

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.

How to match string in regex until a space is encounter? [duplicate]

This question already has answers here:
What do 'lazy' and 'greedy' mean in the context of regular expressions?
(13 answers)
Closed 5 years ago.
I have a piece of text that I need to match anything between <latex and </latex> but not the text and an equivalent quantity of
Which given has the same divisor of <latex>5</latex> and an equivalent quantity of <latex>(5 + 2) \div 5</latex>?
I've tried with the regex \&lt\;(latex).+(latex)\&gt\;([^\s]) but it doesn't stop until the last </latex>in the line.
You need to use a non-greedy match
\&lt\;(latex).+?(latex)\&gt\;