I would like to use regex in my java program to recognize some functions of my lines. I have this type of string:
`-Author- wrote (-hh -: - mm -)
So, for example, I have a line with:
Cecco wrote (15:12)
and I have to extract the author fields, hh and mm. Obviously I have some kind of limitation:
hh and mm must be numbers
author hasn't any restrictions
I've to consider space between "has wrote" and (
I don’t know how I can use regex, could you help me?
EDIT: I add my fragment:
String mRegex = "(\\s)+ has wrote \\((\\d\\d):(\\d\\d)\\)";
Pattern mPattern = Pattern.compile(mRegex);
String[] str = {
"Cecco CQ has wrote (14:55)",
"yesterday you has wrote that I'm crazy",
"Simon has wrote (yesterday)",
"John has wrote (22:32)",
"James has wrote(22:11)",
"Tommy has wrote (xx:ss)"
};
for(String s : str) {
Matcher mMatcher = mPattern.matcher(s);
while (mMatcher.find()) {
System.out.println(mMatcher.group());
}
}
source
share