Regex to get 7 digit number or 7 digit number(6745923) followed by a letter

I need to extract a 7 digit number (6745923) or 7 digit number followed by a (4354678/T) or just a letter: (3546735M)

The below will get the 7 digit numeber but not sure how to get the letters or the forward slash

Sample Text: 1726297T KEVIN GAF RE483948xxxxxxx


give a try:




If i was given the below string it would return “2005739” however i would not expect it to return anything as there is no space after that number. I would like it to only return the string that has a space after it if possible


give a try on

\d{7}\/?[A-Za-z]?\ note after last \ there is space within the pattern

Would there be a way of doing a check on both options to see what is returned?

didnt get you. running both patterns or a combined pattern? But when the first pattern failed, so it will bring again wrong results back.

Let me suggest following: Maybe the first provided samples can be interpretated as values without surrounding () so we can do:

word boundary to begin, optional space on end of pattern

otherwise please provide a clear set of samples representing the variants of your data if a next iteration is needed


1 Like

Thank you for the help on this. nearly have it. Its returning everything i want but one exception.

See below. It should not be returning anything here as i want 7 digit numbers only(or with letters and / at the end)


I think i have it with the below. Look correct?


just trim it after retrieval and then it could work.
With your modification maybe the last \ ? will become obsolete as an ending space is set as mandatory

How would you suggest trimming after retrieval?

I see what you mean with my suggestion requiring a space after it for it to work…

So the ones i have marked in red are the ones i don’t want to retrieve

just provide a new complete list as text (so we can copy and paste) with samples and the information what should be found and what should be ignored. So we will try to tune the pattern

Here is a sample of items i want to retrieve. in bold

1710838T ROCONN E200106
f 5 1666288/T
1611364T PCOFYRO I245585
fff 1054460T S CREANE I20118
1048782T IE2001061725471
1047233/T TJ OWL IE20013203
JLH 1716917T E20010
47393 3747575

Here is a sample of items i do not want to retrieve. in bold

1400003201 IE20
BUNP CHQ 704521922

UN CHQ 332514102
UN CQ 324437834
UNP HQ 217500625

we will have a look on this

1 Like

have a look here:



Looks good. thank you very much

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.