fork download
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3. import java.util.regex.*;
  4. import java.util.stream.Collectors;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. for (String item : findBits("no binary numbers here 3434. Hey friend this is a 1. Those are 1001, 1010, 1011, 1100, 1101. This is a long value 1010101010 and this one as well 1010101010101011. 0 + 0 is a also a 0."))
  11. System.out.println(item);
  12. }
  13.  
  14. public static List<String> findBits(String text) {
  15. Pattern pattern = Pattern.compile("\\b(?>1(?:01)*0?|0(?:10)*1?)\\b");
  16. Matcher matcher = pattern.matcher(text);
  17. return matcher
  18. .results().map(MatchResult::group)
  19. .collect(Collectors.toList());
  20. }
  21.  
  22. }
Success #stdin #stdout 0.08s 49296KB
stdin
Standard input is empty
stdout
1
1010
1010101010
0
0
0