fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "\t\t\tHello I am studying regex!\n\t\t\tThis is a line in the text.\n\t\t\t\tDon't need to add this line\n\t\tnor this line.\n\t\t\tBut this line should be included.";
  11. Pattern pattern = Pattern.compile("(?:\\G(?!^)\\h+|^\t{3})(\\S+)", Pattern.MULTILINE);
  12. Matcher matcher = pattern.matcher(s);
  13. while (matcher.find()){
  14. System.out.println("Match: '" + matcher.group(1) + "', Start: " + matcher.start(1));
  15. }
  16. }
  17. }
Success #stdin #stdout 0.06s 2184192KB
stdin
Standard input is empty
stdout
Match: 'Hello', Start: 3
Match: 'I', Start: 9
Match: 'am', Start: 11
Match: 'studying', Start: 14
Match: 'regex!', Start: 23
Match: 'This', Start: 33
Match: 'is', Start: 38
Match: 'a', Start: 41
Match: 'line', Start: 43
Match: 'in', Start: 48
Match: 'the', Start: 51
Match: 'text.', Start: 55
Match: 'But', Start: 113
Match: 'this', Start: 117
Match: 'line', Start: 122
Match: 'should', Start: 127
Match: 'be', Start: 134
Match: 'included.', Start: 137