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 →
^\d{12}\_[A-C]\s?(\d+)?\.(jpg|pdf|png|jpeg)
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 →
\s?
This tells the engine that there could be a space at that particular location.