Q:

Regex for finding http and https url from a string

I have a string which contains multiple url starting from http and https I need to fetch all those url and put into a list.
I have tried below code.
List<String> httpLinksList = new ArrayList<>();

String hyperlinkRegex = "((http:\/\/|https:\/\/)?(([a-zA-Z0-9-]){2,}\.){1,4}([a-zA-Z]){2,6}(\/([a-zA-Z-_\/\.0-9#:?=&;,]*)?)?)";

String synopsis = "This is http://stackoverflow.com/questions and  https://test.com/method?param=wasd The code below catches all urls in text and returns urls in list";
    Pattern pattern = Pattern.compile(hyperlinkRegex);
    Matcher matcher = pattern.matcher(synopsis);
    while(matcher.find()){
        System.out.println(matcher.find()+"  "+matcher.group(1)+"  "+matcher.groupCount()+"  "+matcher.group(2));

        httpLinksList.add(matcher.group());
    }

    System.out.println(httpLinksList);

I need below result 
[http://stackoverflow.com/questions,
https://test.com/method?param=wasd]
But getting below output
[https://test.com/method?param=wasd]

A:

This regex will match all the valid urls, including FTP and other 
String urlRegex = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class xmlValue {
    public static void main(String[] args) {
String text = "This is http://stackoverflow.com/questions and https://test.com/method?param=wasd The code below catches all urls in text and returns urls in list";
        System.out.println(extractUrls(text));
    }

    public static List<String> extractUrls(String text)
    {
        List<String> containedUrls = new ArrayList<String>();
        String urlRegex = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
        Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
        Matcher urlMatcher = pattern.matcher(text);

        while (urlMatcher.find())
        {
            containedUrls.add(text.substring(urlMatcher.start(0),
                    urlMatcher.end(0)));
        }

        return containedUrls;
    }
}

Output:

[http://stackoverflow.com/questions,
  https://test.com/method?param=wasd]

credits @BullyWiiPlaza

