- Oct 31, 2004
- 776
- 0
- 76
Hey guys,
I'm trying to process a CSV that has some garbage data plus the data I actually want. So in short, I want to find the lines that look like this:
,,,,,ATT,,,PM,,Date,,G,,G,,G,G,,
where the four Gs could be G, R, Y or -. So I'm using the regex expression: [GRY-],,.
I've tested the expression against the string at regexplanet.com and the pattern is found in the string... but for some reason it's not working out in java, which leads me to believe I may be using one of the classes improperly. That said, I haven't found my error either, so a helping hand would be cool
Thanks!
edit:
problem was i was using the matches() method as opposed to the find() method
I'm trying to process a CSV that has some garbage data plus the data I actually want. So in short, I want to find the lines that look like this:
,,,,,ATT,,,PM,,Date,,G,,G,,G,G,,
where the four Gs could be G, R, Y or -. So I'm using the regex expression: [GRY-],,.
I've tested the expression against the string at regexplanet.com and the pattern is found in the string... but for some reason it's not working out in java, which leads me to believe I may be using one of the classes improperly. That said, I haven't found my error either, so a helping hand would be cool
Thanks!
Code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class regextest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Pattern dashboard = Pattern.compile("[GRY-],,");
Matcher fit = dashboard.matcher(",,,,,ATT,,,PM,,Date,,G,,G,,G,G,,");
if(fit.matches()){
System.out.println("found G");
} else {
System.out.println("didnt find G");
}
}
}
edit:
problem was i was using the matches() method as opposed to the find() method
Last edited:
