Hi, im working with the Java Regex class and so im parsing some text. each piece of text is in a separate line. here's a sample of the text:
this is textHello world
buzzinga!
Makmende says hi
Makmende has poked u. dnt try poking him back!
young, forever young
another one from ozeki
Sample text message
Hello world
Hello world
gfxchgfj gh jkgjkg
Oya! Jikakamueni bwana.
Oya!
Yes!
important Yellow
21 M 23415 GOOD
20 F 51433 BAD
23 F 31532 TRUE
20 M 54143 BAD
im interested in the last 4 texts(highlighted) and any other text thats in that format. My regex for sorting this text is "(\\d{2})\\s([MF])\\s(\\d{5})\\s([a-zA-Z0-9]*)"
My code for working it out is:
String smstext = txtsmslist.getText();
String smsformat = "(\\d{2})\\s([MF])\\s(\\d{5})\\s([a-zA-Z0-9]*)";
Pattern pattern = Pattern.compile(smsformat);//pattern has the regex used for searching
//pattern.compile(smsformat, Pattern.MULTILINE);
Matcher matcher =pattern.matcher(smstext); //matcher is the test text to search through
if (matcher.find()){
System.out.println("Found value: "+ matcher.group(0));
txtparselist.setText(matcher.group(0));
}else{
JOptionPane.showMessageDialog(null,"No Matching texts","No Match",JOptionPane.INFORMATION_MESSAGE);
System.out.println("NO MATCH");
}
using this code, i have managed to pick out the first entry i.e 20 F 51433 BAD only but i need to match all of the remaining similar text i.e ny
20 F 51433 BAD
23 F 31532 TRUE
20 M 54143 BAD
and any other text in that format that i may be added to this list.
PS: the text above is in a textpane and not in a file. i only wish to put the output text to a file.
Someone please help me out.