Reputation: 13
A user can put a file in the server if the file name matches the following criteria:
It has to start with abc, then a dot, and a number.
Valid file names:
abc.2344
abc.111
Invalid:
abcd.11
abc.ab12
What would be the regex? I can't just use abc.*.
Upvotes: 1
Views: 3509
Reputation: 26086
\d+ and [0-9]+ still fall afoul of his requirement that "abcd.11" be invalid.
In Perl you could say:
/^abcd.\d{3,}$/
To indicate "abcd." followed by at least 3 digits. Not all regex languages support this syntax so inspect your documentation.
Upvotes: 0
Reputation: 82734
Or a bit more verbose (= readable):
^abc\.[0-9]+$
where square brackets denote groups of characters.
By the way: The caret (^) means "start" and the dollar means "end" of the string in question (sometimes ^ and $ can mean start and end of a single line. It depends).
Upvotes: 0