Thank you Florian and Ben, that was a life saver.
Ben: Sadly work has me lingering on page 157 for 2 days straight now :/
(inspiring and great book!)
I don't really need the date time values for much other than drawing a small graph in Processing, so I´ll take that hurdle when it comes up in the book :)
Florian: Thanks for the link, I had been there before but had a hard time getting the syntax to compile in Processing, but your example helped out with that part.
I implemented the rest of the values with the logic of Florians example
but here is, especially for my own amusement, a short run through I made from RTM ;)
after dissecting the example, for others having trouble.
compile(".*\\\"([0-9]{2}-[0-9]{2}-200[0-9]{1})\\\".*")
" start the expression:
. any character except line breaks
* 0 or more of the previous characters in the string.
So .* means - we don't care what ever comes before in this string.
\\\ escape characters for the \ in the string, as it is in the original string:
" as it is in the original string, i.e. this is part of the string not the regex.
( start of a group, meaning: if the regex finds a match, then the part of the string incapsulated with (string here) will be stored in m.group(1);
[0-9]{2} means, any number and the {2} concatenated on the end of the expression means any number of 2 characters i size. e.g. 12 or 45, i other words 00-99.
- part of the string, not the regex.
[0-9]{2} the same as the previous.
-200[0-9]{1} means the string must contain 200x where the x is a number between 0 and 9 (the script will only go up to the year 2009, could be
written -[0-9]{4} to cover the year 0 to 9999 ... but hey, the data is all ready there and only involves 2007 and 2008.
\\\ escape characters for the \" and it ends with:
.* meaning, we don't care what ever comes after this part.
The finished script looks like this:
Quote:
/* this is how the values in the loaded text looks like
[#date: "27-06-2008", #start: "14:10:52", #history: [21: 1, 31: 6], #duration: 11]
*/
String[] records;
String[] dateArray;
String[] timeArray;
String[] durationArray;
void setup()
{
size(200, 200);
background(0);
records = loadStrings("staticticsWave.txt");
parseData(records);
}
void parseData(String[] records)
{
dateArray = new String[records.length];
timeArray = new String[records.length];
durationArray = new String[records.length];
Pattern date = Pattern.compile(".*([0-9]{2}-[0-9]{2}-200[0-9]{1}).*([0-9]{2}:[0-9]{2}:[0-9]{2}).*#duration:\\s([0-9]{0,}).*");
for(int i = 0; i < records.length; i++)
{
Matcher m = date.matcher(records[i]);
if(m.matches())
{
dateArray[i] = m.group(1);
timeArray[i] = m.group(2);
durationArray[i] = m.group(3);
println(i + ": Date: " + dateArray[i] + " - Time: " + timeArray[i] + " - Duration: " + durationArray[i]);
}
}
}
Thanks again guys for the quick help !
Ricki G