Here you can find the source of extractURIFromText(String texto)
public static String extractURIFromText(String texto)
//package com.java2s; /*//from ww w.j a v a2 s .c om public static boolean save(Model modelo, String filename) { try { BufferedWriter out = new BufferedWriter(new FileWriter(filename)); // RDFDataMgr.write(System.out, modelo, Lang.TURTLE) ; RDFDataMgr.write(out, modelo, Lang.TURTLE) ; out.close(); } catch (IOException ex) { Logger.getLogger("licenser").warn("Error saving file. " + ex.getMessage()); return false; } return true; }*/ import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String extractURIFromText(String texto) { try { URI uri = new URI(texto); String suri = uri.toString(); System.out.println(suri); return suri; } catch (Exception e) { List<String> uris = extractUrls(texto); for (String uri : uris) { System.out.println("Candidato: " + uri); return uri; } } return ""; } 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; } }