I need help to match a string with a regex. An example of the string is
"Longitude: 34.847368\nLatitude: 30.435345\nAltitiude: 130.34554"
So in this string, the numbers can change, and its possible there is no decimal value.
When I try this code,
Pattern pattern = Pattern.compile("Longitude: -?\\d+(\\.\\d+)?\nLatitude: -?\\d+(\\.\\d+)?\nAltitude: -?\\d+(\\.\\d+)?");
I get an error saying \. is an invalid escape sequence, can any one help?
You have to use a double slash, otherwise Java sees it as a String escape sequence, not a Regex escape sequence. Try this: