Hi all,
I can have lines like these which I need to parse and retrieve values from:
'Name=ABC Occupation=SSS Age=23'
'Name=BBB Occupation=TTT'
'Name=BBB Occupation=TTT Age=34' etc. The age field is optional and times it won't be present.
This is my
java code:
String regex = "Name=([A-Z]*)\\sOccupation=([A-Z]*)\\sAge=([0-9]*)"
Matcher matcher = Pattern.compile(reHeaderFormat).matcher(line);
if (matcher.find()) {
String name = matcher.group(1);
String occupation = matcher.group(2);
int age = Integer.parseInt(matcher.group(3));
} else{
//not matching
}
I need to change the regex expression to make the Age field optional, That is, if age field is present retrieve the value, else ignore. With my current expression only those lines with Age field are matching. Please help.
Thanks,
Saud