List of usage examples for java.util.regex Pattern matcher
public Matcher matcher(CharSequence input)
From source file:com.rslakra.java.TestUrlConnection.java
public static void main(String[] args) { String urlString = "https://devamatre.com/"; HttpResponse httpResponse = HTTPHelper.executeGetRequest(urlString, null, true); System.out.println(httpResponse.getRequestHeaders()); String formActionValue = extractFormActionValue(httpResponse.getDataBytes()); System.out.println("\nformActionValue:\n" + formActionValue); String dataString = new String(httpResponse.getDataBytes()); Pattern pattern = Pattern.compile("\""); Matcher matcher = pattern.matcher(dataString); if (matcher.matches()) { System.out.println("Matched\n"); System.out.println(matcher.group(1)); }// w w w . j av a 2s . c o m System.out.println(StringEscapeUtils.unescapeHtml(urlString)); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("java", Pattern.CASE_INSENSITIVE); String candidateString = "Java. java JAVA jAVA"; Matcher matcher = p.matcher(candidateString); // display the latter match System.out.println(candidateString); matcher.find(11);/*from w w w .j a v a 2 s.c o m*/ System.out.println(matcher.group()); // display the earlier match System.out.println(candidateString); matcher.find(0); System.out.println(matcher.group()); }
From source file:Main.java
public static void main(String[] args) { // A group of 3 digits followed by 7 digits. String regex = "\\b(\\d{3})\\d{7}\\b"; // Compile the regular expression Pattern p = Pattern.compile(regex); String source = "12345678, 12345, and 9876543210"; // Get the Matcher object Matcher m = p.matcher(source); // Start matching and display the found area codes while (m.find()) { String phone = m.group(); String areaCode = m.group(1); System.out.println("Phone: " + phone + ", Area Code: " + areaCode); }//from w ww .j av a2 s .c o m }
From source file:Main.java
public static void main(String[] args) { String hello = "HelloxxxHelloxxxHello"; // String you want to 'examine' Pattern pattern = Pattern.compile("Hello"); // Pattern string you want to be // matched Matcher matcher = pattern.matcher(hello); int count = 0; while (matcher.find()) { count++; // count any matched pattern }//w w w.j a v a 2s . c o m System.out.println(count); }
From source file:musiccrawler.MusicCrawler.java
public static void main(String[] args) { String test = "\"Yeu"; String regex = "^\"|\"$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(test); System.out.println(test);// ww w . j a v a 2s .c om if (m.find()) { System.out.println(test.replaceAll(regex, "")); } }
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("Java"); String candidateString = "Java Java Java."; // Attempt to match the candidate String. Matcher matcher = p.matcher(candidateString); // loop though and display all matches while (matcher.find()) { System.out.println(matcher.group()); }/* w ww . j a v a 2s. c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Compile regular expression String patternStr = "b"; Pattern pattern = Pattern.compile(patternStr); // Determine if there is an exact match CharSequence inputStr = "a b c"; Matcher matcher = pattern.matcher(inputStr); boolean matchFound = matcher.matches(); // Try a different input matcher.reset("b"); matchFound = matcher.matches();/*from www .j ava 2 s . co m*/ // Determine if pattern matches beginning of input matchFound = matcher.lookingAt(); }
From source file:CanonEqDemo.java
public static void main(String[] args) { String pattStr = "\u00e9gal"; // Zgal String[] input = { "\u00e9gal", // Zgal - this one had better match :-) "e\u0301gal", // e + "Combining acute accent" "e\u02cagal", // e + "modifier letter acute accent" "e'gal", // e + single quote "e\u00b4gal", // e + Latin-1 "acute" };//from w w w .j a v a 2s .c o m Pattern pattern = Pattern.compile(pattStr, Pattern.CANON_EQ); for (int i = 0; i < input.length; i++) { if (pattern.matcher(input[i]).matches()) { System.out.println(pattStr + " matches input " + input[i]); } else { System.out.println(pattStr + " does not match input " + input[i]); } } }
From source file:HrefMatch.java
public static void main(String[] args) { try {/*w ww . j a v a 2s . c o m*/ // get URL string from command line or use default String urlString; if (args.length > 0) urlString = args[0]; else urlString = "http://java.sun.com"; // open reader for URL InputStreamReader in = new InputStreamReader(new URL(urlString).openStream()); // read contents into string builder StringBuilder input = new StringBuilder(); int ch; while ((ch = in.read()) != -1) input.append((char) ch); // search for all occurrences of pattern String patternString = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>]*)\\s*>"; Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); String match = input.substring(start, end); System.out.println(match); } } catch (IOException e) { e.printStackTrace(); } catch (PatternSyntaxException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Pattern pattern = Pattern.compile("<Mark([^>]*)>"); String myString = "this is a test <Mark this is a test> " + "<i>a</i> <Mark t> <b>x+y</b> <Mark 123>"; Matcher matcher = pattern.matcher(myString); while (matcher.find()) { System.out.println(matcher.group(1)); }/*from ww w. j av a 2 s .co m*/ }