I want to get a list of all possible values for a regular expression.
Input :
2W
9WW
7W0W3
where W can be any digit from 0 to 9. i.e. W = [0-9]
Output:
20,21,22,....29
900,901,...910,911,...999
70003,70013,70023,...71003,72003,...79093
What I did :
I'm using Java and decided to create an ArrayList of Integers.
I created a method ArrayList<Integer> getNumbers(String regex).
ArrayList<Integer> getNumbers(String regex){
ArrayList<Integer> fullList = new ArrayList<Integer>();
char[] cArray = regex.toCharArray(); //converted the string into a character array.
for(int i=1;i<cArray.length;i++) {
if(cArray[i] == 'W') {
for(int j=0;j<10;j++) {
//I'm not sure what goes here
fullList.add(the number with 'w' at this index replaced by 'j');
}
}
}
return fullList;
}
Is there any better way or library functions available to generate all such numbers?
How can I achieve this?