Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an alphabet method #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/ru/lanwen/verbalregex/VerbalExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ public Builder nonSpace() {
return this.add("(?:\\S)");
}

/**
* Add alphabet character: [a-zA-Z]
* @return this builder
*/
public Builder alphabet() {
return this.add("(?:[a-zA-Z])");
}

/*
--- / end of predefined character classes
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/ru/lanwen/verbalregex/PredefinedCharClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PredefinedCharClassesTest {
public static final String DIGITS = "0123456789";
public static final String NON_LETTERS = ";'[]{}|?/";
public static final String SPACE = " \t\n\f\r";
public static final String LETTERS_ONLY_WORD = "q";

@Test
public void testWordChar() throws Exception {
Expand Down Expand Up @@ -97,4 +98,15 @@ public void testWord() throws Exception {
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), is(LETTERS_NO_DIGITS + DIGITS));

}

@Test
public void testAlphabet() throws Exception {
VerbalExpression regex = regex().alphabet().build();

assertThat("matches on letters", regex, matchesTo((LETTERS_ONLY_WORD)));
assertThat("not matches on digit", regex, not(matchesTo(DIGITS)));
assertThat("Extracts wrong chars",
regex.getText(LETTERS_ONLY_WORD + DIGITS + NON_LETTERS + SPACE), equalTo(LETTERS_ONLY_WORD));

}
}