Python regex.fullmatch() Examples

The following are 6 code examples of regex.fullmatch(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module regex , or try the search function .
Example #1
Source File: _wikilist.py    From wikitextparser with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
        self,
        string: Union[str, MutableSequence[str]],
        pattern: str,
        _match: Match = None,
        _type_to_spans: Dict[str, List[List[int]]] = None,
        _span: List[int] = None,
        _type: str = None,
    ) -> None:
        super().__init__(string, _type_to_spans, _span, _type)
        self.pattern = pattern
        if _match:
            self._match_cache = _match, self.string
        else:
            self._match_cache = fullmatch(
                LIST_PATTERN_FORMAT.replace(
                    b'{pattern}', pattern.encode(), 1),
                self._shadow,
                MULTILINE,
            ), self.string 
Example #2
Source File: utils.py    From paper2remarkable with MIT License 5 votes vote down vote up
def is_url(string):
    # pattern adapted from CleverCSV
    pattern = "((https?|ftp):\/\/(?!\-))?(((([\p{L}\p{N}]*[\-\_]?[\p{L}\p{N}]+)+\.)+([a-z]{2,}|local)(\.[a-z]{2,3})?)|localhost|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\:\d{1,5})?))(\/[\p{L}\p{N}_\/()~?=&%\-\#\.:+]*)?(\.[a-z]+)?"
    string = string.strip(" ")
    match = regex.fullmatch(pattern, string)
    return match is not None 
Example #3
Source File: புணர்ச்சி.py    From pytamil with MIT License 5 votes vote down vote up
def getmatchingவிதிகள்(நிலைமொழி, வருமொழி):
    தொடர்மொழி_விதிகள் =[]
    நிலைமொழிவிரி = எழுத்து.உயிர்மெய்விரி(நிலைமொழி)
    வருமொழிவிரி  = எழுத்து.உயிர்மெய்விரி(வருமொழி)

    for விதி in விதிகள்:
        if regex.fullmatch(விதி.நிலைமொழி_regex, நிலைமொழிவிரி ) and \
             regex.fullmatch(விதி.வருமொழி_regex, வருமொழிவிரி ):
             தொடர்மொழி_விதிகள்.append(விதி)

    # print(தொடர்மொழி_விதிகள்)
    return தொடர்மொழி_விதிகள் 
Example #4
Source File: _wikilist.py    From wikitextparser with GNU General Public License v3.0 5 votes vote down vote up
def _match(self):
        """Return the match object for the current list."""
        cache_match, cache_string = self._match_cache
        string = self.string
        if cache_string == string:
            return cache_match
        cache_match = fullmatch(
            LIST_PATTERN_FORMAT.replace(
                b'{pattern}', self.pattern.encode(), 1),
            self._shadow,
            MULTILINE)
        self._match_cache = cache_match, string
        return cache_match 
Example #5
Source File: normal_form.py    From CleverCSV with MIT License 5 votes vote down vote up
def is_elementary(cell):
    return not (
        regex.fullmatch("[a-zA-Z0-9\.\_\&\-\@\+\%\(\)\ \/]+", cell) is None
    ) 
Example #6
Source File: opcua_connector.py    From thingsboard-gateway with Apache License 2.0 4 votes vote down vote up
def __search_node(self, current_node, fullpath, search_method=False, result=None):
        if result is None:
            result = []
        try:
            if regex.match(r"ns=\d*;[isgb]=.*", fullpath, regex.IGNORECASE):
                if self.__show_map:
                    log.debug("Looking for node with config")
                node = self.client.get_node(fullpath)
                if node is None:
                    log.warning("NODE NOT FOUND - using configuration %s", fullpath)
                else:
                    log.debug("Found in %s", node)
                    result.append(node)
            else:
                fullpath_pattern = regex.compile(fullpath)
                for child_node in current_node.get_children():
                    new_node = self.client.get_node(child_node)
                    new_node_path = '\\\\.'.join(char.split(":")[1] for char in new_node.get_path(200000, True))
                    if self.__show_map:
                        log.debug("SHOW MAP: Current node path: %s", new_node_path)
                    new_node_class = new_node.get_node_class()
                    regex_fullmatch = regex.fullmatch(fullpath_pattern, new_node_path.replace('\\\\.', '.')) or \
                                      new_node_path.replace('\\\\', '\\') == fullpath.replace('\\\\', '\\') or \
                                      new_node_path.replace('\\\\', '\\') == fullpath
                    regex_search = fullpath_pattern.fullmatch(new_node_path.replace('\\\\.', '.'), partial=True) or \
                                      new_node_path.replace('\\\\', '\\') in fullpath.replace('\\\\', '\\')
                    if regex_fullmatch:
                        if self.__show_map:
                            log.debug("SHOW MAP: Current node path: %s - NODE FOUND", new_node_path.replace('\\\\', '\\'))
                        result.append(new_node)
                    elif regex_search:
                        if self.__show_map:
                            log.debug("SHOW MAP: Current node path: %s - NODE FOUND", new_node_path)
                        if new_node_class == ua.NodeClass.Object:
                            if self.__show_map:
                                log.debug("SHOW MAP: Search in %s", new_node_path)
                            self.__search_node(new_node, fullpath, result=result)
                        elif new_node_class == ua.NodeClass.Variable:
                            log.debug("Found in %s", new_node_path)
                            result.append(new_node)
                        elif new_node_class == ua.NodeClass.Method and search_method:
                            log.debug("Found in %s", new_node_path)
                            result.append(new_node)
        except CancelledError:
            log.error("Request during search has been canceled by the OPC-UA server.")
        except BrokenPipeError:
            log.error("Broken Pipe. Connection lost.")
        except OSError:
            log.debug("Stop on scanning.")
        except Exception as e:
            log.exception(e)