/** * Attempts to match the entire region against the pattern. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods. </p> * * @return <tt>true</tt> if, and only if, the entire region sequence * matches this matcher's pattern */ public boolean matches() { return match(from, ENDANCHOR); }
/** * Attempts to match the entire region against the pattern. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods. </p> * * @return <tt>true</tt> if, and only if, the entire region sequence * matches this matcher's pattern */ public boolean matches() { return match(from, ENDANCHOR); }
/** * Attempts to match the input sequence, starting at the beginning of the * region, against the pattern. * * <p> Like the {@link #matches matches} method, this method always starts * at the beginning of the region; unlike that method, it does not * require that the entire region be matched. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods. </p> * * @return <tt>true</tt> if, and only if, a prefix of the input * sequence matches this matcher's pattern */ public boolean lookingAt() { return match(from, NOANCHOR); }
/** * Attempts to match the input sequence, starting at the beginning of the * region, against the pattern. * * <p> Like the {@link #matches matches} method, this method always starts * at the beginning of the region; unlike that method, it does not * require that the entire region be matched. * * <p> If the match succeeds then more information can be obtained via the * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods. </p> * * @return <tt>true</tt> if, and only if, a prefix of the input * sequence matches this matcher's pattern */ public boolean lookingAt() { return match(from, NOANCHOR); }
Matcher urlMatch = url.matcher(line); while (urlMatch.find()) urlsFound.add(urlMatch.match());
final Pattern PATTERN = Pattern.compile("^\\Q(.+?)\\nyo(?:(?!cut me:|\\nyo).)*cut me:\\E", Pattern.DOTALL); final Matcher m = PATTERN.matcher("(.+?)\\nyo(?:(?!cut me:|\\nyo).)*cut me:"); System.out.println(m.match()); // true
static Pattern p = Pattern.compile("(?:P1=(\d*)),\s*(?:P2=(.*?))?,\s*(?:P3=(.*?))?,\s*(?:P4=(.*?))?,\s*(?:P5=(.*?))?"); public ReferenceData(String line) { Matcher m = p.matcher(line); if(m.match()){ P1 = Integer.parseInt(m.group(1)); P2 = m.group(2);//note: this can be null is P2 is not part of the line P3 = m.group(3); P4 = m.group(4); P5 = m.group(5); } }
String patternInLine = ".+\\{$"; String patternNewLine = "^\\{": Pattern p1 = new Pattern(patternInLine); Pattern p2 = new Pattern(patternNewLine); while(in.hasNext()) { String line = in.nextLine(); in.hasNextLine(); Matcher m1 = p1.match(line); Matcher m2 = p2.match(line); if(m1.match()) { //inLine++; } else if (m2.match()) { //newLine++; } else { //other cases } }