I'm a newbie at regex and I'm trying to ignore spaces and punctuation when validating the format of a VAT number.
I have this regular expression: ^BE[0-9]{10,10}$
It works for this: BE1234567890
But I need it to work for these too:
How can I get the Regex to ignore whitespaces and punctuation that I define?
答案 0 :(得分:0)
BE(\s?|:)(\d{10}|\d{3}.\d{3}.\d{3,4})
this is for EXCACTLY your given examples. Note that you might match more digits in the last \d{3,4} to fulfill your needs
答案 1 :(得分:0)
A better idea would be just to strip all spaces and punctuation beforehand, then validate the stripped string with your regex.
But if you really want to, you can do this:
^BE([[:space:][:punct:]]*[0-9]){10}$
This allows arbitrary spaces/punctuation before each digit.