Regex to match a word following spaces and numbers - regex

I have searched around quite a bit, but I haven't found a solution for my problem yet.
I'm trying to create a regex that will allow me to match the following examples:
YOUU 410831 0
MEIU 810851 0
I got to \b(YOUU|MEIU)\w*\b.
But then I can't seem to add a space, then a number, then a space again, and finally a digit. How could I achieve this?

You are looking for something like
[A-Z]+(?:\s+[0-9]+)+
See demo
Or, if there are 2 set groups of numbers after the word, and the 1st number is 6 digits in size, and the last digit is always of size 1:
[A-Z]+\s+[0-9]{6}\s+[0-9]\b
Demo 2
With i option, the words with lowercase letters will also be matched.

Try to use this:
\b(YOUU|MEIU) \d+ \d\b
REGEX DEMO

You are probably looking for this regex?
\b(YOUU|MEIU)\s+\d+\b\s+\d
if the numbers in the middle are always 6 numbers, you may want to fix that with
\b(YOUU|MEIU)\s+\d{6}\b\s+\d

Related

RegEx match everything between 2 characters only if at least 3 characters

I am trying to match all characters between "xAA" and "xFF" but only if theres at least 4 characters between those. Is there a simple way to do this with RegEx?
For example, xAA-12345-xFF should be matched but xAA-1-xFF should be ignored.
My RegEx currently looks like this:
"(?<=\xAA).*(?=\xFF)"
this does match everything between those characters, but i can't find a way on how to only match if at least 4 characters between them, can someone help me?
Quick and dirty hack could be:
"xAA....*xFF"
This requires three (...) characters followed by 0 or more (.*).
Do this:
xAA\S{4,}xFF
\S{4,} matches at least 4 non whitespace characters.
Demo
(?<=xAA-)[0-9]{4,}(?=\-xFF)
retracts 12345 from xAA-12345-xFF in case there are only digits
(?<=xAA-)[0-9a-zA-Z]{4,}(?=\-xFF) if letters or digits are possible
regex101.com

RegEx to match 2-digit number in certain range

I need to create a RegEx to verify the string input to a text box is exactly 2 digits long and is within the range 01-25 or 99.
I am new to creating my own RegEx and came up with:
[01-25,99]{2}
This verifies the number is 2 digits long, but it finds many matches outside of the indicated range.
Character classes can contain character ranges, not value ranges.
Try this alternation:
0[1-9]|1\d|2[0-5]|99
If you want to limit the entire input to be such, wrap in ^ and $:
^0[1-9]|1\d|2[0-5]|99$
This should work:
# ^(?:0[1-9]|1\d|2[0-5]|99)$
^
(?:
0 [1-9]
| 1 \d
| 2 [0-5]
| 99
)
$
Maybe something as dumb as (0[1-9]|1[0-9]|2[0-5]|99)
the way that regex works is as individual numbers, not as a range like you would assume. This means that your pattern :
[01-25,99]
would actually match anything that has a 0,1-2,5, a comma, or a 9 (saying it twice doesn't make a difference), and putting `{2} means that you are matching any string that has both of these in a row.
since it was answered while I was typing this, look at the pattern sln posted for one that should work.
Also like this
[0][1-9]|[1][0-9]|[2][0-5]|[99]

Regex Match if there is space in front

I need a regex which matches with 1 to 6 length digits which is easy \d{1,6}, however I need avoid if there is longer number than 6 digits.
For example, it should match 233 in sentence, my id is 233, but it should not match my id is 222334444
It should only match if there is space before first digit of number.
Thanks
Its hard to tell what the expected character is on either side.
Generally, it could be done using word boundary \b\d{1,6}\b
Use lookarounds.
(?<=^|\s)\d{1,6}(?!\d)
How about?
Online Demo
(?<!\d)\d{1,6}$

Regex of exact length that matches specific group of numbers

I'm looking to build a regex that matches the following group of numbers:
10xxxxxxx
1116xxxxx
143xxxxxx
146xxxxxx
149xxxxxx
159xxxxxx
16xxxxxxx
(note the length is always 9)
where x is any digit. My best attempt yielded this:
/^1[01456][1369]*[6]*[0-9]$/
However, I can't get the length of the string to always be 9. Any ideas?
Edit: Maybe I wasn't clear enough, it needs to match those 7 cases, and ONLY those, inclusively and exclusively.
How about:
^1(?:[06]\d{2}|116|4[369]\d|59\d)\d{5}$
use this pattern
^1[01456](16|3\d|6\d|9\d|\d\d)\d{5}$
Is this what you want?
^(?=[0-9]{9}$)(?:10|1116|143|146|149|159|16)
Demo
This starts by looking at the beginning of the string for exactly 9 digits using a positive lookahead anchored to the end of the string. Then we look for any of your 7 specific groups of numbers that the string can start with.
You can use this regex:
/^1[01456][1369][0-9]{6}$/
Since 3 digits are already matched by first 3 patterns 1, [01456] and [1369] so last one must match exact 6 characters to enforce it a 9 digit input.

match last digits in a long number with regex

I'm real newbie when it comes to Regex so apologies if this 'should' be easy.
I need to match the last 6 digits of a number that has the following format
308950 3200 014559
The first 2 groups of numbers will remain constant (308950 3200) and don't need to be extracted. I am only interested in the last 6 digits.
The full number may contain spaces but these need to be optional.
This has to be done in Regex.
Use regex pattern
(?<=\b308950\s*3200\s*)\d{6}\b
or
\b308950\s*3200\s*(\d{6})\b
This should do it even if there are spaces between the digits
^308950 3200[\d\s]*?((\d\s?){6})$
Group 1 will contain the reqired digits with spaces if any
If the leading numbers will remain constant, you can use:
308950 3200\s*(\d{6})
Alternatively, you could use:
(?:\d+\s)+(\d{6})
Also, if the string will be at the end of the input string, consider adding a $ to the end to signify this (to make sure it'll match the end of the string):
(\d{6})$