madu
madu

Reputation: 53

Regex to match a word following spaces and numbers

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?

Upvotes: 3

Views: 73

Answers (3)

Garis M Suero
Garis M Suero

Reputation: 8169

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

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172548

Try to use this:

\b(YOUU|MEIU) \d+ \d\b

REGEX DEMO

Upvotes: 1

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627103

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.

Upvotes: 2

Related Questions