the question is find all bit sequences which are alternating between 1 and 0, i.e., those that do not have more than 1 or 0 in a row and return it in a list.
what i did so far
public static List<String> findBits(String text) {
Pattern pattern = Pattern.compile("([01])(?!\\1)([01])(?:\\1\\2)*\\1?|(?<!\\S)[01](?!\\S)|1.|0.", Pattern.DOTALL);
Matcher matcher = pattern.matcher(text);
return matcher.results()
.map(String::valueOf)
.collect(Collectors.toList());
it should return
no binary numbers here 3434. -> [] Empty List
Hey friend this is a 1. -> [1]
Those are 1001, 1010, 1011, 1100, 1101 -> [1010]
This is a long value 1010101010 and this one as well 1010101010101011 -> [1010101010]
0 + 0 is a also a 0. -> [0,0,0]