this code is to extract sequential letters from a data-set
import java.util.regex.*;
public class IFS {
public static void main(String[] args) {
String a;
a = "ABC1abc";
regexchecker ("\\D+", a);
}
public static void regexchecker(String theRegex, String stuffToCheck) {
// compiling the regex pattern
Pattern checkRegex = Pattern.compile(theRegex);
// the regex matcher being joined to the pattern
Matcher regexmatcher = checkRegex.matcher(stuffToCheck);
int end = stuffToCheck.length();
for (int i = 0; i < end; i = i + 1) {
for (int j = i + 1; j <= end; ++j) {
regexmatcher.region(i, j);
while (regexmatcher.find()) {
if (regexmatcher.group().length() != 0) {
System.out.println(regexmatcher.group());
}
}
}
}
}
}
OK so I understand that my code will iterate from j to end EVERY TIME but I need it to skip an iteration that gives the same out put.
my output is
- A
- AB
- ABC
- ABC
- ABC a
- ABC ab
- ABC abc
and so on when I want an output like
- A
- B
- C
- a
- b
- c
- AB
- BC
- ab
- bc
- ABC
- abc
Any help is much appreciated. My original data-set is much larger than this but I have used a 7 character set for simplicity
Aucun commentaire:
Enregistrer un commentaire