Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Regex not working

I migrated my project from Eclipse to Android Studio and everything worked fine. In this project I have a Regex which should find all image urls in a json-object I get from an API.

This is the Regex I have:

Pattern pattern = Pattern.compile("https?:\\/\\/[^\"]*?\\.(png|jpe?g|img)");

            Matcher matcher = pattern.matcher(obj.toString());
            while(matcher.find()) {
                ImageBackgroundFetcher.getInstance(mActivity).addImageToLoadingQueue(matcher.group());
            }

obj is the JSONObject I have with the image urls. It looks like the following and I would like to extract the url of the image (the bold marked part) {"image":"http:\/\/www.test.de\/media\/2015\/01\/16\/bildtitel.jpg"}

After I migrate the project from Eclipse to Android Studio this Regex isn't working any longer. The matcher.find()-Method did not return true and Android Studio gives me a warning in the code at the regex part "\\/\\/" where it says "redundant character escape"

I already googled but didn't find a solution. Any ideas how to solve the problem would be great, thanks in advance ;)

like image 730
jennymo Avatar asked Oct 25 '25 00:10

jennymo


1 Answers

You can use AS function to check Regex.

Press Shortcut: Alt+Enter → check regexp enter image description here

Match result]

enter image description here

like image 187
Fantasy Fang Avatar answered Oct 26 '25 13:10

Fantasy Fang