Type the Pattern/Matcher parse of an event line
Type the Pattern/Matcher parse of an event line
Answer
Pattern p = Pattern.compile("Event=(\\w+),time=(\\d+)"); Matcher m = p.matcher(line); if (m.matches()) { String name = m.group(1); long time = Long.parseLong(m.group(2)); }
Two capturing groups: group(1) is the event name, group(2) the digits. matches() requires the whole line to fit the pattern; \\w and \\d are the source escaping of the regex \w and \d.