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

[2973 byte] By [EqAfricaa] at [2007-10-3 4:48:43]
# 1

If you are parsing HTML/XML then unless the source is strictly formatted then you should use a HTML/XML parser.

Attempting to use regexes to do the same will either eventually result in creating a parser or result in a hard to maintain mess.

Strictly formatted usually means that it is machine generated and comes from a single source.

jschella at 2007-7-14 22:53:11 > top of Java-index,Core,Core APIs...
# 2

thank you,

I have made a correction of my code,

if(matcher.find())

have to be while(matcher.find())

I am using regular expressions just for the learning purposes, and this

HTML is just an example, it could be txt or some other file which i want to parse.

best regards,

Nikola

EqAfricaa at 2007-7-14 22:53:11 > top of Java-index,Core,Core APIs...