File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
src/main/java/ru/lanwen/verbalregex Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 4
4
import java .util .regex .Pattern ;
5
5
6
6
import static java .lang .String .valueOf ;
7
+ import static ru .lanwen .verbalregex .VerbalExpression .regex ;
7
8
8
9
public class VerbalExpression {
9
10
@@ -171,6 +172,24 @@ public Builder maybe(final String pValue) {
171
172
return this .then (pValue ).add ("?" );
172
173
}
173
174
175
+ /**
176
+ * Add a regex to the expression that might appear once (or not)
177
+ * Example:
178
+ * The following matches all names that have a prefix or not.
179
+ * VerbalExpression.Builder namePrefix = regex().oneOf("Mr.", "Ms.");
180
+ * VerbalExpression name = regex()
181
+ * .maybe(namePrefix)
182
+ * .space()
183
+ * .zeroOrMore()
184
+ * .word()
185
+ * .oneOrMore()
186
+ * .build();
187
+ * regex.test("Mr. Bond/") //true
188
+ * regex.test("James") //true
189
+ *
190
+ * @param pValue - the string to be looked for
191
+ * @return this builder
192
+ */
174
193
public Builder maybe (final Builder regex ) {
175
194
return this .group ().add (regex .build ().toString ()).endGr ().add ("?" );
176
195
}
You can’t perform that action at this time.
0 commit comments