Rahul Maheshwari Rahul Maheshwari - 2 months ago 14
Python Question

Regex, filter url ending with and without digit

I have below four url out of which I want to filter only two using regex expression.

/chassis/motherboard/cpu <---- this

/chassis/motherboard/cpu/core0

/chassis/motherboard/cpu0 <---- this

/chassis/motherboard/cpu1/core0

I have tried to play around with ^.*[0-9a-z_].cpu but unable to get the solution.

Answer

You can use this regex:

^.*/cpu[0-9]*$

This will match any text that ends with /cpu or /cpy<number>