Exemple #1
0
  @Test
  public void testLineModes() {
    /*
     * Has enhanced line-anchor mode
     */
    String forTest =
        "to be a great man ,you must pay great effort\nAnd you will meet the most difficult things like the bitch\n";
    /*
     * ^ matches at start of string
     */

    long found = RegExpUtils.countFound(RegExpUtils.getMatcher("^", forTest));
    assertEquals(1L, found);
    /*
     * $ matches at end of string,and matches before string-ending newline.
     */
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("$", forTest));
    assertEquals(2L, found);
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("$", forTest));
    assertEquals(2L, found);

    /*
     * In enhanced line-anchor mode ... ^ matches at start of string
     *
     * ^ matches after any newline $ matches at end of string $ matches
     * before any newline \A always matches like normal ^ \Z always matches
     * like normal $ \z always matches only at end of string
     */
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\Z", forTest));
    assertEquals(2L, found);
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\A", forTest));
    assertEquals(1L, found);
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\z", forTest));
    assertEquals(1L, found);

    // multiline mode
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("$", forTest, Pattern.MULTILINE));
    assertEquals(3L, found);
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\A", forTest, Pattern.MULTILINE));
    assertEquals(1L, found);
    /*
     * Always like the normal '$'
     */
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\Z", forTest, Pattern.MULTILINE));
    assertEquals(2L, found);
    /*
     * Always matches end of String.
     */
    found = RegExpUtils.countFound(RegExpUtils.getMatcher("\\z", forTest, Pattern.MULTILINE));
    assertEquals(1L, found);
  }
Exemple #2
0
  @Test
  public void testDigitalMatcher() {

    Matcher matcher = RegExpUtils.getMatcher("[\\d]", "12345d");

    assertEquals(5, RegExpUtils.countFound(matcher));

    matcher = RegExpUtils.getMatcher("\\D", "12345d");

    assertEquals(1, RegExpUtils.countFound(matcher));

    matcher = RegExpUtils.getMatcher("\\D", "12345d");
    RegExpUtils.printFound(matcher, OUTPUT_STRING_WIDTH);
  }
Exemple #3
0
  @Test
  public void defaultMatchModeShouldBeMultiLine() {

    Matcher matcher = RegExpUtils.getMatcher("$", "\n");
    assertEquals(2L, RegExpUtils.countFound(matcher));
  }