Regex to check if filename was followed


I need to check if file name convention was followed with format



Input: 123456789012_A.jpg
Result: True

Input: 123456789012_B 2.jpg
Result: True

Input: 123456789012_C 3.jpg
Result: True

Input: 123456789012_A .jpg
Result: True

It should allow spaces/characters in any position

I 'm using \b(\d{12})_(A|B|C).(jpg|pdf|png|jpeg) BUT it doesn’t allow space in any position.



Try below Regular expression.


1 Like

Hi @mnlatam ,

Sorry but its unclear when you said that the space can be anywhere in the string.
If the examples you have provided are examples of where all the spaces can be, then this ought to work out for you →



If you want a space to show up anywhere in between, or if there is a chance of it showing up anywhere in between, then you can simply add this →


This tells the engine that there could be a space at that particular location.

Kind Regards,
Ashwin A.K

1 Like

@mnlatam This expression is working for both the cases


Case1 : Data with spaces

Case2: Data without spaces

1 Like