File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,15 @@ public boolean testExact(String toTest) {
258
258
public boolean test (String toTest ) {
259
259
return Pattern .compile (this .pattern , this .modifiers ).matcher (toTest ).find ();
260
260
}
261
+
262
+ public String getText (String toTest ) {
263
+ Matcher m = Pattern .compile (this .pattern ).matcher (toTest );
264
+ StringBuilder result = new StringBuilder ();
265
+ while (m .find ()){
266
+ result .append (m .group ());
267
+ }
268
+ return result .toString ();
269
+ }
261
270
262
271
public String toString () {
263
272
return this .pattern .toString ();
Original file line number Diff line number Diff line change 1
1
import org .junit .Test ;
2
2
import org .junit .Before ;
3
3
import org .junit .Ignore ;
4
+
4
5
import static org .junit .Assert .*;
5
6
6
7
public class BasicFunctionalityUnitTests {
@@ -199,4 +200,16 @@ public void testSearchOneLine () {
199
200
testString = "a\n b" ;
200
201
assertTrue ("b is on the second line but we are only searching the first" , testRegex .test (testString ));
201
202
}
203
+
204
+
205
+ @ Test
206
+ public void testGetText () {
207
+ String testString = "123 https://www.google.com 456" ;
208
+ VerbalExpression testRegex = new VerbalExpression ().add ("http" )
209
+ .maybe ("s" ).then ("://" ).then ("www." ).anythingBut (" " )
210
+ .add ("com" );
211
+ assertEquals (testRegex .getText (testString ), "https://www.google.com" );
212
+
213
+ }
214
+
202
215
}
You can’t perform that action at this time.
0 commit comments