Reputation: 1743
I am creating a Restful API on Laravel 5.6. After clients upload image, they send file path. I can validate using mimes
while clients are uploading an image. After that i want to check file path extension using regex. But i have no idea how can i do ?
1.) Client send request -> upload_image (return image path) --> i am using mimes
2.) Client send request -> create_profile with image path --> i want to use regex
I dont know how regex write. Because i really hate regular expressions. I know, i shouldn't ask this question like. But i have to. Please help me ?
I want to control string : 'image-20180306.jpg', if last 3 char or after dot char is jpg, it is ok.
Upvotes: 1
Views: 1253
Reputation: 43169
You can use
^.+\.jpe?g$
# ^ - match start of the string
# .+ - match 1+ chars
# \. - a dot
# jpe?g - jpg or jpeg (? makes the predecessor optional)
# $ - the end of the string
Upvotes: 3