0

I want to match an optionnal specific pattern after a wildcard, how can I achieve this ?

Here is my test string :

RGF0027_a_Test string_987.test_004.jpg

I want to match the _004, it must be optionnal and it can have any text before that.

Here is my current (not working) regex :

^([a-zA-Z0-9]+)_(a_)?.*(_(\d+))?\.\w+$

Of course the problem is that the .* also match the _004. I think the answer is to use assertions but I'm not really good with them ...

Demo on regex101

Community
  • 1
  • 1
Yrtiop
  • 51
  • 15

0 Answers0