Regex help - match any file ending with [0-9].jpg
How do i write a regex to match anything ending with a number, then .jpg.
E.g:
10021321.jpg MATCH
1231.jpg MATCH
xxx.jpg NO MATCH
123123-resized开发者_StackOverflow社区.jpg NO MATCH
^.*[0-9]\.jpg$
will do this. This allows any characters before the final number + .jpg
.
Edit: Since you only want to allow numbers and nothing else in the filename, use
^[0-9]+\.jpg$
(but this is not what you're actually asking in your question).
This should do it: ^\w*?\d+\.jpg$
Edited answer based on comments:
^\d+\.jpg$
If you want to allow only numbers (according to your comment) then do this
^\d+\.jpg$
See it here on Regexr
^
matches the start of the string
$
matches the end of the string
\d
is a digit, some regex engines don't use this then replace just with [0-9]
+
is one or more times
\.
the dot needs to be escaped to match literally otherwise it will match any character
What you're after is:
^\d+\.jpg$
or, if you allow non-numeric characters before the number, then:
^.*\d+\.jpg$
Ignore case variant: (?i)\d\.jpg$
. If you need to match all string, use this: (?i).*?\d\.jpg$
You can use following regex for this.
^\d+?\.jpg$
精彩评论