Regular expressions & java.util.Scanner
I am trying to make a simple txt parser using regular expressions but the problem has
appeared.
The program's code is too long so I have stated only the part of the code implementing
the methoddata_types() which doesn't work properly, it reads only two types (String) and (Boolean). If someone could help me I would be very gratefull.Why method doesn't read the rest of data types in mydata_xml.xml file?
here is the code >
class SimpleScann{
enum PARSE{
TABLE_NAME("(\\w*)"),COLUMN_NAME("(\\w*\\Q(\\E)"),DATA_TYPE("(\\Q(\\E\\w*\\Q)\\E)");
private String $pattern;
PARSE(String pattern){
$pattern=pattern;
}
public String PATTERN(){
return $pattern;
}
}
staticvoid data_types()throws Exception{
File parse_file=new File("data_type.txt");
Scannerscann_input =new Scanner(parse_file);
int flag= Pattern.CASE_INSENSITIVE;
Pattern pattern=Pattern.compile(PARSE.DATA_TYPE.PATTERN(),flag);
Matcher matcher=null;
while(scann_input.hasNextLine()){
matcher=pattern.matcher(scann_input.nextLine());
if(matcher.find()){
System.out.printf("%s\n",matcher.group());
}
}
}
publicstaticvoid main(String args[])
{
try{
data_types();
}catch(Exception e){
e.printStackTrace();
}
}
}
and here is the data_type.txt
<table> Table radi
ako su zatvoreni tagovi<>
<column>
Ime(String), Prezime(String), JMBG(Integer) ,
Enabled(Boolean)
<\column>
best regards,
Nikola Radakovic

