Exemple #1
0
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."

    if _jsre._is_valid(pattern):
       return _jsre.compile(pattern, flags)

    return _pyre().compile(pattern, flags)
Exemple #2
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.search(pattern, string, flags)
    else:
        return _pyre().search(pattern, string, flags)
Exemple #3
0
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."

    if _jsre._is_valid(pattern):
        return _jsre.compile(pattern, flags)

    return _pyre().compile(pattern, flags)
Exemple #4
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.match(pattern, string, flags)
    else:
        return _pyre().match(pattern, string, flags)
Exemple #5
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.search(pattern, string, flags)
    else:
        return _pyre().search(pattern, string, flags)
Exemple #6
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.match(pattern, string, flags)
    else:
        return _pyre().match(pattern, string, flags)
Exemple #7
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.sub(pattern, repl, string, count, flags)
    else:
        return _pyre().sub(pattern, repl, string, count, flags)
Exemple #8
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.sub(pattern, repl, string, count, flags)
    else:
        return _pyre().sub(pattern, repl, string, count, flags)
Exemple #9
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.findall(pattern, string, flags)
    else:
        return _pyre().findall(pattern, string, flags)
Exemple #10
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.split(pattern, string, maxsplit, flags)
    else:
        return _pyre().split(pattern, string, maxsplit, flags)
Exemple #11
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.findall(pattern, string, flags)
    else:
        return _pyre().findall(pattern, string, flags)
Exemple #12
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.split(pattern, string, maxsplit, flags)
    else:
        return _pyre().split(pattern, string, maxsplit, flags)
Exemple #13
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.subn(pattern, repl, string, count, flags)
    else:
        return _pyre().subn(pattern, repl, string, count, flags)
Exemple #14
0
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."""
    if _jsre._is_valid(pattern):
        return _jsre.subn(pattern, repl, string, count, flags)
    else:
        return _pyre().subn(pattern, repl, string, count, flags)
Exemple #15
0
                   as well as the string.
                   "$" matches the end of lines (before a newline) as well
                   as the end of the string.
    S  DOTALL      "." matches any character at all, including the newline.
    X  VERBOSE     Ignore whitespace and comments for nicer looking RE's.
    U  UNICODE     For compatibility only. Ignored for string patterns (it
                   is the default), and forbidden for bytes patterns.

This module also defines an exception 'error'.

"""
import sys
import _jsre
_pymdl = [None]

if not _jsre._is_valid():
   from pyre import *

# public symbols
__all__ = [ "match", "search", "sub", "subn", "split", "findall",
    "compile", "purge", "template", "escape", "A", "I", "L", "M", "S", "X",
    "U", "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
    "UNICODE", 
    # TODO: brython - same exception class in sre_constants and _jsre
    #"error" 
    ]

__version__ = "2.2.1"

# flags
A = ASCII = _jsre.A # assume ascii "locale"
Exemple #16
0
                   as well as the string.
                   "$" matches the end of lines (before a newline) as well
                   as the end of the string.
    S  DOTALL      "." matches any character at all, including the newline.
    X  VERBOSE     Ignore whitespace and comments for nicer looking RE's.
    U  UNICODE     For compatibility only. Ignored for string patterns (it
                   is the default), and forbidden for bytes patterns.

This module also defines an exception 'error'.

"""
import sys
import _jsre
_pymdl = [None]

if not _jsre._is_valid():
    from pyre import *

# public symbols
__all__ = [
    "match",
    "search",
    "sub",
    "subn",
    "split",
    "findall",
    "compile",
    "purge",
    "template",
    "escape",
    "A",