Python re 模块,Match() 实例源码

我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用re.Match()

项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def _processLength(self, lengthMatch):
        """
        Processes the length definition of a netstring.

        Extracts and stores in C{self._expectedPayloadSize} the number
        representing the netstring size.  Removes the prefix
        representing the length specification from
        C{self._remainingData}.

        @raise NetstringParseError: if the received netstring does not
            start with a number or the number is bigger than
            C{self.MAX_LENGTH}.
        @param lengthMatch: A regular expression match object matching
            a netstring length specification
        @type lengthMatch: C{re.Match}
        """
        endOfNumber = lengthMatch.end(1)
        startOfData = lengthMatch.end(2)
        lengthString = self._remainingData[:endOfNumber]
        # Expect payload plus trailing comma:
        self._expectedPayloadSize = self._extractLength(lengthString) + 1
        self._remainingData = self._remainingData[startOfData:]
项目:xphyle    作者:jdidion    | 项目源码 | 文件源码
def _match_to_dict(
            self, match: Match, errors: bool = True) -> Dict[str, Any]:
        """Convert a regular expression Match to a dict of (name, value) for
        all PathVars.

        Args:
            match: A :class:`re.Match`.
            errors: If True, raise an exception for validation failure,
                otherwise return None.

        Returns:
            A (name, value) dict.

        Raises:
            ValueError if any values fail validation.
        """
        return match_to_dict(match, self.path_vars, errors)
项目:xphyle    作者:jdidion    | 项目源码 | 文件源码
def find(
            self, root: PathLike = None,
            recursive: bool = False) -> Sequence[PathInst]:
        """Find all paths in `root` matching this spec.

        Args:
            root: Directory in which to begin the search.
            recursive: Whether to search recursively.

        Returns:
            A sequence of PathInst.
        """
        if root is None:
            root = self.default_search_root()
        find_results = find(
            root, self.pattern, path_types=[self.path_type],
            recursive=recursive, return_matches=True)
        matches = dict(
            (path, self._match_to_dict(match, errors=False))
            for path, match in cast(
                Sequence[Tuple[str, Match[str]]], find_results))
        return [
            path_inst(path, match)
            for path, match in matches.items()
            if match is not None]
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:qiskit-sdk-py    作者:QISKit    | 项目源码 | 文件源码
def _truncate_float(matchobj, format_str='0.2g'):
    """Truncate long floats

    Args:
        matchobj (re.Match object): contains original float
        format_str (str): format specifier
    Returns:
        returns truncated float
    """
    if matchobj.group(0):
        return format(float(matchobj.group(0)), format_str)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:pelisalacarta-ce    作者:pelisalacarta-ce    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:plugin.video.streamondemand-pureita    作者:orione7    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:kodi-tk_del    作者:hubsif    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:mechanize    作者:python-mechanize    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start] + match.string[end:]
项目:pmatic    作者:LarsMichelsen    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:deb-python-eventlet    作者:openstack    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:addon    作者:alfa-addon    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:xphyle    作者:jdidion    | 项目源码 | 文件源码
def match_to_dict(
        match: Match, path_vars: Dict[str, PathVar],
        errors: bool = True) -> Dict[str, Any]:
    """Convert a regular expression Match to a dict of (name, value) for
    all PathVars.

    Args:
        match: A re.Match.
        path_vars: A dict of PathVars.
        errors: If True, raise an exception on validation error, otherwise
            return None.

    Returns:
        A (name, value) dict.

    Raises:
        ValueError if any values fail validation.
    """
    match_groups = match.groupdict()
    try:
        return dict(
            (name, var(match_groups.get(name, None)))
            for name, var in path_vars.items())
    except ValueError:
        if errors:
            raise
        else:
            return None

# pylint: disable=no-member
项目:xphyle    作者:jdidion    | 项目源码 | 文件源码
def find(
            self, root: PathLike = None, 
            path_types: Sequence[PathTypeArg] = 'f',
            recursive: bool = False) -> Sequence[PathInst]:
        """Find all paths matching this PathSpec. The search starts in 'root'
        if it is not None, otherwise it starts in the deepest fixed directory
        of this PathSpec's DirSpec.

        Args:
            root: Directory in which to begin the search.
            path_types: Types to return -- files ('f'), directories ('d') or
                both ('fd').
            recursive: Whether to search recursively.

        Returns:
            A sequence of PathInst.
        """
        if root is None:
            if self.fixed_dir:
                root = str(self.dir_spec)
            else:
                root = self.dir_spec.default_search_root()

        files = find(
            root, self.pattern, path_types=path_types, recursive=recursive,
            return_matches=True)

        return [
            path_inst(path, match_to_dict(match, self.path_vars))
            for path, match in cast(Sequence[Tuple[str, Match[str]]], files)]
项目:BruteXSS    作者:rajeshmajumdar    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]