probe_scv_drone
06-10-2009, 09:41 PM
Hi, I'm trying to parse some text with java's regex and nothing seems to be working -_-;;;
In this code all I am trying to do is parse a string for words and it doesn't work:
Pattern pattern = Pattern.compile(".*(\\w+).*");
Matcher matcher = pattern.matcher(buffer);
To get the split string I am trying both this:
String[] matches = pattern.split(buffer);
System.out.println("split produced:");
for(int i = 0; i < matches.length; i++){
System.out.println(matches[i]);
}
and this:
matcher.find(0);
System.out.println(matcher.group());
while(matcher.find()){
System.out.println(matcher.group(1));
}
What I am tyring to do is split a string like this:
Time IRIGB (s) Lat Ltn (deg) Lon Ltn (deg) Tas stbd (m/s) wind speed Hg (m/s) wind direction Hg (deg t)
into substrings like this:
Time IRIGB (s)
Lat Ltn (deg)
Lon Ltn (deg)
Tas stbd (m/s)
wind speed Hg (m/s)
wind direction Hg (deg t)
In this code all I am trying to do is parse a string for words and it doesn't work:
Pattern pattern = Pattern.compile(".*(\\w+).*");
Matcher matcher = pattern.matcher(buffer);
To get the split string I am trying both this:
String[] matches = pattern.split(buffer);
System.out.println("split produced:");
for(int i = 0; i < matches.length; i++){
System.out.println(matches[i]);
}
and this:
matcher.find(0);
System.out.println(matcher.group());
while(matcher.find()){
System.out.println(matcher.group(1));
}
What I am tyring to do is split a string like this:
Time IRIGB (s) Lat Ltn (deg) Lon Ltn (deg) Tas stbd (m/s) wind speed Hg (m/s) wind direction Hg (deg t)
into substrings like this:
Time IRIGB (s)
Lat Ltn (deg)
Lon Ltn (deg)
Tas stbd (m/s)
wind speed Hg (m/s)
wind direction Hg (deg t)