JAVA-11241 Added missing pom.xml for container modules and other cleanup
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.regex.array;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.*;
|
||||
|
||||
class RegexMatches {
|
||||
|
||||
String[] regexMatch(String strSearch)
|
||||
{
|
||||
List<String> matchesList = new ArrayList<String>();
|
||||
String stringToSearch = strSearch;
|
||||
Pattern p1 = Pattern.compile("780{1}\\d{7}");
|
||||
Matcher m1 = p1.matcher(stringToSearch);
|
||||
while (m1.find())
|
||||
{
|
||||
matchesList.add(m1.group());
|
||||
}
|
||||
int sizeOfNewArray = matchesList.size();
|
||||
String newArrayOfMatches[] = new String[sizeOfNewArray];
|
||||
matchesList.toArray(newArrayOfMatches);
|
||||
return newArrayOfMatches;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.regex.array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class RegexMatchesUnitTest {
|
||||
|
||||
@Test
|
||||
void whenFourNums_thenFourMatches() {
|
||||
RegexMatches rm = new RegexMatches();
|
||||
String actual[] = rm.regexMatch("7801111211fsdafasdfa 7802222222 sadfsadfsda7803333333 sadfdasfasd 7804444444");
|
||||
|
||||
assertArrayEquals(new String[] {"7801111211", "7802222222", "7803333333", "7804444444"}, actual, "success");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenThreeNums_thenThreeMatches() {
|
||||
RegexMatches rm = new RegexMatches();
|
||||
String actual[] = rm.regexMatch("7801111211fsdafasdfa 780222222 sadfsadfsda7803333333 sadfdasfasd 7804444444");
|
||||
|
||||
assertArrayEquals(new String[] {"7801111211", "7803333333", "7804444444"}, actual, "success");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenZeroNums_thenZeroMatches() {
|
||||
RegexMatches rm = new RegexMatches();
|
||||
String actual[] = rm.regexMatch("78011111fsdafasdfa 780222222 sadfsadfsda78033333 sadfdasfasd 7804444");
|
||||
|
||||
assertArrayEquals(new String[] {}, actual, "success");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user