Re: Regex to extract lines
Hello,
I see no space in your regular expressions, perhaps your problem came from there.
Note: You can replace [0-9] by \ d
by the following line in your code.
Code:
if(Pattern.games(F\\d +\\. "Line) | | Pattern.games("\\.\\d + "Line))
First replace this line in your code and then see if it works or not and if you are getting any error then post back with the error.
Re: Regex to extract lines
Hello,
Eve I had a similar kind of a problem, so i am interested in this thread, the solution you mentioned, i have tried it
Code:
Note: You can replace [0-9] by \ d
Code:
if(Pattern.games(F\\d +\\. "Line) | | Pattern.games("\\.\\d + "Line))
This line of the code does not work, thought thanks for the help.
I have tried something else here, just have a look
Code:
while((ln = in.readLine())!=null){
if(Pattern.games("^ F\\d +\\. "ln) | | Pattern.games("^\\.\\d + "ln)){
out.write(+ Onln System.getProperty("ln.separator"));
}
}
Any more help on this is highly appreciated. Thanks in advance.
Re: Regex to extract lines
Hello,
In fact I just realize that you forgot to add ".*" at the end of the regular expression . Indeed, it was defined early in our regular expressions, not the full lines.
Code:
if(Pattern.games(F\\d +\\. .*"Line) | | Pattern.games("\\.\\d + .* "Line))
Just think once before you include this in your code.
F00.2 * atypical or mixed (G30.8 +)
and
Quote:
F00.9 * unspecified (G30.9 +)
correpondent does not pattern.
Re: Regex to extract lines
Hello,
Here is my updated code, have a look at it and if you find any corrections in that to be made, then you can guide me.
Code:
public class Extraction {
/ ** Creates a new instance of extraction * /
Public Extraction() {
}
Public static void hand(String[] args) {
String ln;
BufferedReader in;
BufferedWriter out;
for(int i =1; i <=10; i + +){
try{
in =new BufferedReader(new FileReader(". / sources / sourcei + +. txt "));
try{
out =new BufferedWriter(new FileWriter(". / output / exiti + +. txt "));
try{
while((ln = in.readLine())!=null){
if(Pattern.games("^ F\\d +\\. .*"ln) | | Pattern.games("^\\.\\d + .* "ln) | | Pattern.games("^\\.\\d +\\* .*"ln)){
out.write(+ Onln System.getProperty("ln.separator"));
}
}
System.out.System.out.println("File"i + +"Done!");
} finally{
out.close();
}
}finally{
in.close();
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
Re: Regex to extract lines
Hello,
No, the problem is with the regular expression, in fact it is specifically that X can be a decimal number (see your example) which was not included in the regular expressions given so far.
For example, first it gives something like
Code:
"^ F\\d + (\\.\\d +)? .* "
I hope you are understanding the thing here. If you have any more queries to ask in this then you can post here.