Reputation: 861
Assume we have some string of defined length, that could contain some delimiters, that are used only for user-friendly view.
Example: 9-digit string, "123456789", that could be presented like "123,456,789" or "123.456.789" or "1-234-5-67-89" or "123 456 789"
What I need, is a regexp, that could count length ignoring that delimiters.
Something like [\d|,\.\-\s]{9}
, but with only \d counting into {9} (any number of delimiter characters allowed... optionally, delimiter characters shouldn't exceed two in a row)
Upvotes: 0
Views: 1929
Reputation: 655269
Instead of bothering my head about finding an appropriate regular expression that might do this, I would rather use more simple regular expressions to either:
Upvotes: 0
Reputation: 523304
^[-.,\s]*(?:\d[-.,\s]*){9}$
optionally, delimiter characters shouldn't exceed two in a row:
^[-.,\s]{0,2}(?:\d[-.,\s]{0,2}){9}$
Upvotes: 6