My regular expression is
<source media="(min-width: 0px)" sizes="70px" data-srcset="(.*?)"/>
The text I'm testing my regex with is
<source media="(min-width: 0px)" sizes="70px" data-srcset="https://static2.therichestimages.com/wordpress/wp-content/uploads/2014/05/52f81afc8b39c.jpg?q=50&fit=crop&w=70&h=70 70w"/>
It does not detect a URL inside the data-srcset attribute.
My code is
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
private static final String IMG_PREFIX =
"<source media=\"(min-width: 0px)\" sizes=\"70px\" data-srcset=\"";
private static final String IMG_SUFFIX = "\"/>";
public static void main(String[] args) {
String line = "<source media=\"(min-width: 0px)\" sizes=\"70px\" data-srcset=\"https://static1.therichestimages.com/wordpress/wp-content/uploads/2012/06/Michael-Bloomberg.jpg?q=50&fit=crop&w=70&h=70 70w\"/>";
Pattern pattern = Pattern.compile(IMG_PREFIX + "(.*?)" + IMG_SUFFIX);
Matcher matcher = pattern.matcher(line);
System.out.println(matcher.find());
}
}
Edit: the production code is using this HTML source rather than just a single line.