[BAEL-5518] Create Array of Regex Matches (#12052)
* opokharel's code for "A quick and practical example of Hexagonal Architecture in Java" * opokharel - added unit Tests * [BAEL-5518] by @opokharel * updated Files * updated formatting * whitespaceFix * [BAEL-5518] Create Array of Regex Matches * reCreatingPR
This commit is contained in:
24
regexMatchesToArray/src/regex/array/RegexMatches.java
Normal file
24
regexMatchesToArray/src/regex/array/RegexMatches.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user