fork download
  1. import java.util.regex.*;
  2. import java.util.*;
  3. import java.util.stream.Collectors;
  4.  
  5. class Ideone
  6. {
  7. public static Pattern pattern = Pattern.compile("\\b(?!\\d*(\\d)\\1)[10]+\\b");
  8.  
  9. public static List<String> findBits(String text) {
  10. Matcher matcher = pattern.matcher(text);
  11. return pattern.matcher(text)
  12. .results()
  13. .map(MatchResult::group)
  14. .collect(Collectors.toList()); //.toArray(String[]::new);
  15. }
  16.  
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. List<String> r = 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.");
  20. System.out.println(r);
  21. }
  22. }
Success #stdin #stdout 0.1s 49052KB
stdin
Standard input is empty
stdout
[1, 1010, 1010101010, 0, 0, 0]