Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    private final static Pattern patternURL = Pattern.compile("(?i)http[s]?://[\\w\\.\\-/:?=&%]+");

    private static String makeUrlHerf(String content) {
        if (content.trim().length() == 0) {
            return content;
        }
        StringBuffer urlStringBuffer = new StringBuffer();

        Matcher matcherUrl = patternURL.matcher(content);
        while (matcherUrl.find()) {

            String url = matcherUrl.group();
            //            System.out.println("URL:" + url);
            String urlToHref = "<a href=\"" + url + "\">" + url + "</a>";
            matcherUrl.appendReplacement(urlStringBuffer, urlToHref);

        }
        matcherUrl.appendTail(urlStringBuffer);
        return urlStringBuffer.toString();
    }
}