Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Stephen Le Bel
Added: Jul 25, 2018 9:22 PM
Views: 9
Tags: no tags
  1.  //private static final Pattern urlPattern = Pattern.compile("(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?");
  2. //
  3.        
  4.         Matcher m = urlPattern.matcher(sentence);
  5.  
  6.                 // if an occurrence if a pattern was found in a given string...
  7.                 if (m.find()) {
  8.                     foundList.add(m.group(0));
  9.                     // ...then you can use group() methods.
  10. //                    System.out.println(m.group(0)); // whole matched expression
  11. //                    System.out.println(m.group(1)); // first expression from round brackets (Testing)
  12. //                    System.out.println(m.group(2)); // second one (123)
  13. //                    System.out.println(m.group(3)); // third one (Testing)
  14.                    
  15.                 }