Skip to content

Commit 1739d58

Browse files
committed
Merge branch 'master' of https://github.com/mgramin/JavaVerbalExpressions into mgramin-master
Conflicts: src/test/java/BasicFunctionalityUnitTests.java
2 parents 663787f + 2afb034 commit 1739d58

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/main/java/VerbalExpression.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@ public boolean test(final String pToTest) {
269269
private VerbalExpression(final Builder pBuilder) {
270270
pattern = pBuilder.pattern;
271271
}
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+
}
272281

273282
@Override
274283
public String toString() {

src/test/java/BasicFunctionalityUnitTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
2-
import static org.junit.Assert.*;
31
import org.junit.Test;
2+
import org.junit.Before;
3+
import org.junit.Ignore;
4+
import static org.junit.Assert.*;
45

56
public class BasicFunctionalityUnitTests {
6-
77
@Test
88
public void testSomething() {
99
VerbalExpression testRegex = new VerbalExpression.Builder().something().build();
@@ -197,4 +197,18 @@ public void testSearchOneLine() {
197197

198198
assertTrue("b is on the second line but we are only searching the first", testRegex.test("a\nb"));
199199
}
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+
}

0 commit comments

Comments
 (0)