File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,15 @@ public boolean test(final String pToTest) {
269
269
private VerbalExpression (final Builder pBuilder ) {
270
270
pattern = pBuilder .pattern ;
271
271
}
272
+
273
+ public String getText (String toTest ) {
274
+ Matcher m = pattern .matcher (toTest );
275
+ StringBuilder result = new StringBuilder ();
276
+ while (m .find ()){
277
+ result .append (m .group ());
278
+ }
279
+ return result .toString ();
280
+ }
272
281
273
282
@ Override
274
283
public String toString () {
Original file line number Diff line number Diff line change 1
-
2
- import static org .junit .Assert .*;
3
1
import org .junit .Test ;
2
+ import org .junit .Before ;
3
+ import org .junit .Ignore ;
4
+ import static org .junit .Assert .*;
4
5
5
6
public class BasicFunctionalityUnitTests {
6
-
7
7
@ Test
8
8
public void testSomething () {
9
9
VerbalExpression testRegex = new VerbalExpression .Builder ().something ().build ();
@@ -197,4 +197,18 @@ public void testSearchOneLine() {
197
197
198
198
assertTrue ("b is on the second line but we are only searching the first" , testRegex .test ("a\n b" ));
199
199
}
200
- }
200
+
201
+ @ Test
202
+ public void testGetText () {
203
+ String testString = "123 https://www.google.com 456" ;
204
+ VerbalExpression testRegex = new VerbalExpression .Builder ().add ("http" )
205
+ .maybe ("s" )
206
+ .then ("://" )
207
+ .then ("www." )
208
+ .anythingButNot (" " )
209
+ .add ("com" ).build ();
210
+ assertEquals (testRegex .getText (testString ), "https://www.google.com" );
211
+
212
+ }
213
+
214
+ }
You can’t perform that action at this time.
0 commit comments