Using REGEX to pull the info I want out of the following strings?


I am working on a website that has product codes with the format t1234_blu where the first character is always a letter and the next 4 are numbers. There is then alway three letters after the underscore.

I have been trying, and failing to come up with a REGEX to pull product codes out of the following strings:



Could someone please show me how this would be done is the most robust way possible?

Any help is much appreciated.


Based on your description:


You can easily test and interpret regexes with a tool like

PS: the example you gave has 4 digits after the letter, not 3.

A few slight modifications I’d make to ArtemPetrov’s regex:


1 Like