Regex- match on a specific string with any two digit integer in it?

P.V. :

I have a list of filenames that look like this: red.t<0 padded int>z.white.blue<0 padded int>.ab00.txt2 For example:

red.t01z.white.blue12.ab00.txt2
red.t02z.white.blue45.ab00.txt2
red.t03z.white.blue09.ab00.txt2

I want to match on this sequence, for any two digit number. The 00 near the end is constant, and it shouldn't match on any other values there. ie, this wouldn't match red.t03z.white.blue09.ab01.txt2.

I tried red.t[0-9]*z.white.blue[0-9]*.ab00.txt, but that only works when I have the first [0-9]* in there, the second one makes it no longer match. What is the solution to this?

The fourth bird :

You could use anchors to assert the start and end of the string, escape the dot to match it literally and use a quantifier 0-9[{2} to match 2 digits.

^red\.t[0-9]{2}z\.white\.blue[0-9]{2}\.ab00\.txt2$

Regex demo

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=297997&siteId=1