I have a string like this:
String = IDENTIFIER: 115956 LATITUDE: 40.104730 LONGITUDE: -88.228798 DATE RIGHTS
I want to only match and print out115956 | 40.104730 | -88.228798
. How do I do it with regular expression?
Here is my code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test3
{
private static String REGEX = "\\d+\\.\\d";
private static String INPUT = "IDENTIFIER: 115956 LATITUDE: 40.104730 LONGITUDE: -88.228798 ";
private static String REPLACE = "-";
public static void main(String[] args) {
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT); // get a matcher object
StringBuffer sb = new StringBuffer();
while(m.find()){
m.appendReplacement(sb,REPLACE);
}
m.appendTail(sb);
System.out.println(sb.toString());
}
}
But my results are like this: IDENTIFIER: 115956 LATITUDE: -04730 LONGITUDE: --28798
.