Joe Howard
asked on
regex needed
What regex would capture the file name not including _[S|M|L|thumb].jpg in all the following examples:
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/AS6_1683-77_S.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/AS6_1683-77_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/AS6_1683-77.jpg?response-content-disposition
AS6_1683-77
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/AS6_3900-136_thumb.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/AS6_3900-136_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/AS6_3900-136.jpg?response-content-disposition
AS6_3900-136
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_S.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_L.jpg?response-content-disposition
hand-drawn-illustration-of -cocktail- vector-col lection_X1 EVoU
Note: it should be the same regex for all of them.
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/AS6_1683-77_S.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/AS6_1683-77_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/AS6_1683-77.jpg?response-content-disposition
AS6_1683-77
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/AS6_3900-136_thumb.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/AS6_3900-136_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/AS6_3900-136.jpg?response-content-disposition
AS6_3900-136
https://d1yl1kh78jj1rr.cloudfront.net/thumbnail/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_S.jpg
https://d1yl1kh78jj1rr.cloudfront.net/preview/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_M.jpg
https://d1yl1kh78jj1rr.cloudfront.net/content/hand-drawn-illustration-of-cocktail-vector-collection_X1EVoU_L.jpg?response-content-disposition
hand-drawn-illustration-of
Note: it should be the same regex for all of them.
ASKER
I need a regex, the system I use requires a regex input to do its processing.
For me this works:
You can test and tweak and understand it @ https://regex101.com/
/.*\/(.*?)_?[SMLt]?[humb]*\.jpg.*/
You can test and tweak and understand it @ https://regex101.com/
return psFileName.replaceFirst(". */(.*?)(_( S|M|L|thum b))?\\.jpg .*", "$1");
ASKER
Doesn't work for me, please see it live at http://www.regexr.com/3ch31
ASKER
ozo doesn't work either http://www.regexr.com/3ch34
try:
^.*\/(.*(\_(S|M|L|thumb))?\.jpg).*$
please note that the regexr site shows only first match from the whole string, so if you paste all of the URLs in the regexr only the first will match, you can delete one by one and see if the next one matches - as you would also process each line by line
If you add the flag global you have 9 matches
/https://.*/(.*)_/m
HTH,Dan
with my regex if you go with global and multiline flags all lines match
http://www.regexr.com/3ch3 7
http://www.regexr.com/3ch3
This makes me think my solution works: https://regex101.com/r/zL8dS5/1
Errata:
/https://.*/(.*)_(M|L|thumb)*.*\./g
Hi,
pls try
pls try
.*\/(.*?)(_([SML]|thumb))?\.jpg.*
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, thanks.
Thanx 4 axxepting
Open in new window