INNER CODE UNIT · Python

map_to_regex

arnonym/ha-plugins · ha-sip/src/account.py:179

        def map_to_regex(st: str) -> str:
            if st == '{*}':
                return '.*'
            if st == '{?}':
                return '.'
            return re.escape(st)
        if not number:
            return False
        for n in number_list:
            # split by {*} and {?} keeping delimiters
            n_split = re.split(r'(\{\*}|\{\?})', n)
            n_regex = '^' + ''.join(map(map_to_regex, n_split)) + '$'
            match = re.match(n_regex, number)
            if match:
                return True
        return False

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…