I have a file containing several lines similar to:
Name: Peter
Address: St. Serrano número 12, España
Country: Spain
And I need to extract the address using a regular expression, taking into account that it can contain dots, special characters (ñ, ç), áéíóú...
The current code works, but it looks quite ugly:.
Pattern p = Pattern.compile("^(.+?)Address: ([a-zA-Z0-9ñÑçÇáéíóú., ]+)(.+?)$",
Pattern.MULTILINE | Pattern.DOTALL);
Matcher m = p.matcher(content);
if (m.matches()) { ... }
Edit: The Address field could also be divided into multiple lines
Name: Peter
Address: St. Serrano número 12,
Madrid
España
Country: Spain
Edit: I can't use a Properties object or a YAML parser, as the file contains other kind of information, too.