/java/

Guava CharMatcher

2014-05-30 00:30:08

@Test
public void testChar() {
    assertThat(CharMatcher.DIGIT.removeFrom("m1i2c3h4a5l")).isEqualTo("michal");
    assertThat(CharMatcher.JAVA_LETTER.removeFrom("m1i2c3h4a5l")).isEqualTo("12345");

    assertThat(CharMatcher.DIGIT.retainFrom("m1i2c3h4a5l")).isEqualTo("12345");
    assertThat(CharMatcher.JAVA_LETTER.retainFrom("m1i2c3h4a5l")).isEqualTo("michal");

    assertThat(CharMatcher.anyOf("mi").removeFrom("m12345i")).isEqualTo("12345");
    assertThat(CharMatcher.BREAKING_WHITESPACE.removeFrom("michal\nszal")).isEqualTo("michalszal");
}

<dependency>
<groupid>com.google.guava</groupid>
<artifactid>guava</artifactid>
<version>17.0</version>
</dependency>