Reputation: 95
I want split bellow string with numbers means coordinates. Please help me split pattern in java
34°6′19″N 74°48′58″E / 34.10528°N 74.81611°E / 34.10528; 74.81611This is very good place for tour
This string I want separate string
1. 34°6′19″N 74°48′58″E / 34.10528°N 74.81611°E / 34.10528; 74.81611
2. This is very good place for tour
I have used possible patterns, but not get proper results
1. (?=\\d)(?<!\\d)
2. (?<=[0-9])(?=[a-zA-Z])
3. [^A-Z0-9]+|(?<=[A-Z])(?=[0-9])|(?<=[0-9])(?=[A-Z])
Upvotes: 2
Views: 374
Reputation: 36304
Try :
public static void main(String[] args) {
String s = "34°6′19″N 74°48′58″E / 34.10528°N 74.81611°E / 34.10528; 74.81611This is very good place for tour";
String[] arr = s.split("(?<=\\d)(?=[A-Z])");
System.out.println(arr[0]);
System.out.println(arr[1]);
}
O/P :
34°6′19″N 74°48′58″E / 34.10528°N 74.81611°E / 34.10528; 74.81611
This is very good place for tour
s.split("(?<=\\d)(?=[A-Z])")
--> Split based on any capital character preceeded by a digit - don't capture / lose any char
Upvotes: 3