Suggest a regex for this pattern

Hi, how to break the text below based on the template

  • More than one place
  • followed by a capital letter

Sample text:

Overview This is my sample program Written in java 

Required conclusion

 Overview This is my sample program Written in java 

I tried the following regex but didn't work

 "\\s{2,}\\[Az]" 

Please suggest me a regex to separate text

+4
source share
2 answers

Use a positive forward forecast ( (?=[AZ]) ) to match the uppercase alphabet without using:

 String text = "Overview This is my sample program Written in java"; String[] words = text.split("\\s{2,}(?=[AZ])"); for (String word : words) System.out.println(word); 
+6
source
  String text = "Overview This is my sample program Written in java"; String[] words = text.split("\\s{2,}"); for (String word : words) { System.out.println(word); } 

You do not need to use a positive look ahead.

0
source

Source: https://habr.com/ru/post/1498902/


All Articles