A binary gap within a positive number ```num``` is any sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of  ```num```. 
    For example:
    ```9``` has binary representation ```1001``` and contains a binary gap of length ```2```.
    ```529``` has binary representation ```1000010001``` and contains two binary gaps: one of length ```4``` and one of length ```3```.
    ```20``` has binary representation ```10100``` and contains one binary gap of length ```1```.
    ```15``` has binary representation ```1111``` and has ```0``` binary gaps.
    Write ```function gap(num)```
that,  given a positive ```num```,  returns the length of its longest binary gap. The function should return ```0``` if ```num``` doesn't contain a binary gap.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def gap(num):
	

Solutions:
def gap(num):
	s = bin(num)[2:].strip('0')
	return max(map(len, s.split('1')))


import re

def gap(num):
	x = re.findall('(?=(10+1))', bin(num).lstrip('0b'))
	return max([len(i) - 2 for i in x]) if x else 0


import re

def gap(num):
	n = 0
	for m in re.finditer('(?=(1(0+)1))', bin(num)[2:]):
		n = max(n, m.end(2) - m.start(2))
	return n


def gap(num):
	binary = bin(num)[2:]
	gaps = binary.strip('0').split('1')
	return len(max(gaps))


def gap(num):
	return len(max(bin(num)[2:].split('1')[1:-1]))


def gap(num):
	return len(max(bin(num)[2:].rstrip('0').split('1')))


import re

def gap(num):
	num = bin(num)[2:]
	return max(map(len, re.findall('(?<=1)0+(?=1)', num)), default=0)


def gap(num):
	return max((len(seq) for seq in format(num, 'b').strip('0').split('1')))


from regex import findall

def gap(num):
	if num < 2:
		return 0
	return max(map(len, findall('1(0*)(?=1)', f'{num:b}')))