zoukankan      html  css  js  c++  java
  • 正则表达式

    # public interface
    
    def match(pattern, string, flags=0):
        """Try to apply the pattern at the start of the string, returning
        a match object, or None if no match was found."""
        return _compile(pattern, flags).match(string)
    
    def fullmatch(pattern, string, flags=0):
        """Try to apply the pattern to all of the string, returning
        a match object, or None if no match was found."""
        return _compile(pattern, flags).fullmatch(string)
    
    def search(pattern, string, flags=0):
        """Scan through string looking for a match to the pattern, returning
        a match object, or None if no match was found."""
        return _compile(pattern, flags).search(string)
    
    def sub(pattern, repl, string, count=0, flags=0):
        """Return the string obtained by replacing the leftmost
        non-overlapping occurrences of the pattern in string by the
        replacement repl.  repl can be either a string or a callable;
        if a string, backslash escapes in it are processed.  If it is
        a callable, it's passed the match object and must return
        a replacement string to be used."""
        return _compile(pattern, flags).sub(repl, string, count)
    
    def subn(pattern, repl, string, count=0, flags=0):
        """Return a 2-tuple containing (new_string, number).
        new_string is the string obtained by replacing the leftmost
        non-overlapping occurrences of the pattern in the source
        string by the replacement repl.  number is the number of
        substitutions that were made. repl can be either a string or a
        callable; if a string, backslash escapes in it are processed.
        If it is a callable, it's passed the match object and must
        return a replacement string to be used."""
        return _compile(pattern, flags).subn(repl, string, count)
    
    def split(pattern, string, maxsplit=0, flags=0):
        """Split the source string by the occurrences of the pattern,
        returning a list containing the resulting substrings.  If
        capturing parentheses are used in pattern, then the text of all
        groups in the pattern are also returned as part of the resulting
        list.  If maxsplit is nonzero, at most maxsplit splits occur,
        and the remainder of the string is returned as the final element
        of the list."""
        return _compile(pattern, flags).split(string, maxsplit)
    
    def findall(pattern, string, flags=0):
        """Return a list of all non-overlapping matches in the string.
    
        If one or more capturing groups are present in the pattern, return
        a list of groups; this will be a list of tuples if the pattern
        has more than one group.
    
        Empty matches are included in the result."""
        return _compile(pattern, flags).findall(string)
    
    def finditer(pattern, string, flags=0):
        """Return an iterator over all non-overlapping matches in the
        string.  For each match, the iterator returns a match object.
    
        Empty matches are included in the result."""
        return _compile(pattern, flags).finditer(string)
    # public interface

    def match(pattern, string, flags=0):
    """Try to apply the pattern at the start of the string, returning
    a match object, or None if no match was found."""
    return _compile(pattern, flags).match(string)

    def fullmatch(pattern, string, flags=0):
    """Try to apply the pattern to all of the string, returning
    a match object, or None if no match was found."""
    return _compile(pattern, flags).fullmatch(string)

    def search(pattern, string, flags=0):
    """Scan through string looking for a match to the pattern, returning
    a match object, or None if no match was found."""
    return _compile(pattern, flags).search(string)

    def sub(pattern, repl, string, count=0, flags=0):
    """Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl. repl can be either a string or a callable;
    if a string, backslash escapes in it are processed. If it is
    a callable, it's passed the match object and must return
    a replacement string to be used."""
    return _compile(pattern, flags).sub(repl, string, count)

    def subn(pattern, repl, string, count=0, flags=0):
    """Return a 2-tuple containing (new_string, number).
    new_string is the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in the source
    string by the replacement repl. number is the number of
    substitutions that were made. repl can be either a string or a
    callable; if a string, backslash escapes in it are processed.
    If it is a callable, it's passed the match object and must
    return a replacement string to be used."""
    return _compile(pattern, flags).subn(repl, string, count)

    def split(pattern, string, maxsplit=0, flags=0):
    """Split the source string by the occurrences of the pattern,
    returning a list containing the resulting substrings. If
    capturing parentheses are used in pattern, then the text of all
    groups in the pattern are also returned as part of the resulting
    list. If maxsplit is nonzero, at most maxsplit splits occur,
    and the remainder of the string is returned as the final element
    of the list."""
    return _compile(pattern, flags).split(string, maxsplit)

    def findall(pattern, string, flags=0):
    """Return a list of all non-overlapping matches in the string.

    If one or more capturing groups are present in the pattern, return
    a list of groups; this will be a list of tuples if the pattern
    has more than one group.

    Empty matches are included in the result."""
    return _compile(pattern, flags).findall(string)

    def finditer(pattern, string, flags=0):
    """Return an iterator over all non-overlapping matches in the
    string. For each match, the iterator returns a match object.

    Empty matches are included in the result."""
    return _compile(pattern, flags).finditer(string)
  • 相关阅读:
    这就是搜索引擎--读书笔记六--索引的查询
    这就是搜索引擎--读书笔记五--索引的建立与更新
    JavaWeb学习总结第四篇--Servlet开发
    算法帝国--读书笔记
    这就是搜索引擎--读书笔记四--索引基础
    这就是搜索引擎--读书笔记三
    Python学习总结之五 -- 入门函数式编程
    ASP.NET-FineUI开发实践-4(二)
    ASP.NET-FineUI开发实践-4
    ASP.NET-FineUI开发实践-3
  • 原文地址:https://www.cnblogs.com/NewTaul/p/7077379.html
Copyright © 2011-2022 走看看