Skip to content

Commit b157f25

Browse files
committed
add an alphabet method
1 parent 4ee34e6 commit b157f25

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/ru/lanwen/verbalregex/VerbalExpression.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ public Builder nonSpace() {
335335
return this.add("(?:\\S)");
336336
}
337337

338+
/**
339+
* Add alphabet character: [a-zA-Z]
340+
* @return this builder
341+
*/
342+
public Builder alphabet() {
343+
return this.add("(?:[a-zA-Z])");
344+
}
338345

339346
/*
340347
--- / end of predefined character classes

src/test/java/ru/lanwen/verbalregex/PredefinedCharClassesTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class PredefinedCharClassesTest {
2020
public static final String DIGITS = "0123456789";
2121
public static final String NON_LETTERS = ";'[]{}|?/";
2222
public static final String SPACE = " \t\n\f\r";
23+
public static final String LETTERS_ONLY_WORD = "q";
2324

2425
@Test
2526
public void testWordChar() throws Exception {
@@ -97,4 +98,15 @@ public void testWord() throws Exception {
9798
regex.getText(LETTERS_NO_DIGITS + DIGITS + NON_LETTERS + SPACE), is(LETTERS_NO_DIGITS + DIGITS));
9899

99100
}
101+
102+
@Test
103+
public void testAlphabet() throws Exception {
104+
VerbalExpression regex = regex().alphabet().build();
105+
106+
assertThat("matches on letters", regex, matchesTo((LETTERS_ONLY_WORD)));
107+
assertThat("not matches on digit", regex, not(matchesTo(DIGITS)));
108+
assertThat("Extracts wrong chars",
109+
regex.getText(LETTERS_ONLY_WORD + DIGITS + NON_LETTERS + SPACE), equalTo(LETTERS_ONLY_WORD));
110+
111+
}
100112
}

0 commit comments

Comments
 (0)