Is there a number wildcard character in java? I'm opening a file and looking at a list of data and I need to differentiate between three pieces of information that start with "M". However, one of them has numbers directly following it and the other two have letters that follow. I was wondering if there was a way to check if there was a number after the letter with a wildcard character. I'm sure you could do this with ASCII, but I also am unsure of how to execute that.
EDIT: I'm still having issues, so here is my code.
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class addSevTest{
public static void main(String[] args) throws IOException{
FileReader fr = new FileReader("output6.txt");
BufferedReader br = new BufferedReader(fr);
String line;
Pattern pattern = Pattern.compile(br.readLine());
Matcher matcher = pattern.matcher(br.readLine());
List<String> list = new ArrayList<String>();
while ((line = br.readLine()) != null){
if(line.contains("100%") || line.contains("70%") || matcher.find("[.][1-9]")){
list.add(line);
list.add(" 2");
list.add("\n");
//System.out.println('Using String matches method: '+line.matches('.M'));
}else if(line.startsWith("MDRALM")){
list.add(line);
list.add(" 3");
list.add("\n");
}else if(line.startsWith("SOL") || line.startsWith("I/O") || line.startsWith("AH") || line.startsWith("LT")){
continue;
}else{
list.add(line);
list.add(" 1");
list.add("\n");
}
}
/*while ((line = br.readLine()) != null){
if(line.contains("CP")){
list.add(line);
list.add("\n");
}
}*/
br.close();
FileWriter writer = new FileWriter("addSevTest_O.txt");
for(String str: list){
writer.write(str);
}
writer.close();
}
}
java.util.regex.PatternandMatcherclasses along with your Regex to evaluate the String.