2

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])

1 Answers1

3

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

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
  • Can you also explain the `s.split("(?<=\\d)(?=[A-Z])")` sequence on a granular level on how exactly it works?. You can edit your post and share the explanation, this way it'll be more clearer to view. – Suresh Feb 16 '18 at 07:18