示例#1
0
def parse(s):
    """Regular expression parser

    :param s: Regular expression
    :type s: str
    :rtype: list
    """
    if IS_PY3:
        r = sre_parse.parse(s, flags=U)
    else:
        r = sre_parse.parse(s.decode('utf-8'), flags=U)
    return list(r)
示例#2
0
文件: exrex.py 项目: crono/exrex
def parse(s):
    """Regular expression parser

    :param s: Regular expression
    :type s: str
    :rtype: list
    """
    if IS_PY3:
        r = sre_parse.parse(s, flags=U)
    else:
        r = sre_parse.parse(s.decode("utf-8"), flags=U)
    return list(r)
示例#3
0
def parse(s):
    """Regular expression parser
    :param s: Regular expression
    :type s: str
    :rtype: list
    """
    r = sre_parse.parse(s)
    return list(r)
示例#4
0
def parse(s):
    """Regular expression parser

    :param s: Regular expression
    :type s: str
    :rtype: list
    """
    r = sre_parse.parse(s)
    return list(r)
示例#5
0
def rand_reg(source, flag=0, pattern=None):
    """
    generates a random string (which may include utf-8 encoded unicode) as per a re pattern string
    :param source: re pattern string
    :param flag: 0 for ascii and 32 (re.UNICODE) for unicode
    :param pattern: not used parameter
    :return: generated string
    """
    result = []
    try:
        result.append(deduce(flag, *sre_parse.parse(source, flag, pattern)))
    except error:
        return u"" if flag == re.UNICODE else ""
    else:
        return ("".join(result)).decode('utf-8') if flag == re.UNICODE else "".join(result)
示例#6
0
文件: exrex.py 项目: dnet/exrex
def parse(s):
    """docstring for parse"""
    r = sre_parse.parse(s)
    print r
    return _p(list(r))
示例#7
0
from re import sre_parse, error

from core.regexps.ops import deduce


def rand_reg(source, flag=0, pattern=None):
    """
    generates a random string (which may include utf-8 encoded unicode) as per a re pattern string
    :param source: re pattern string
    :param flag: 0 for ascii and 32 (re.UNICODE) for unicode
    :param pattern: not used parameter
    :return: generated string
    """
    result = []
    try:
        result.append(deduce(flag, *sre_parse.parse(source, flag, pattern)))
    except error:
        return u"" if flag == re.UNICODE else ""
    else:
        return ("".join(result)).decode('utf-8') if flag == re.UNICODE else "".join(result)


if __name__ == '__main__':
    import re
    p = [r'\w+\W?[ab0-9]{1,2}3{3}(\w|3?|ab){,2}', r'.*', r'3ab[1-2]?\W(?P<g>ab)']
    flag = 0
    for _p in p:
        rr = rand_reg(_p, flag=flag)
        print '"%s"' % rr
        print re.match(_p, rr, flags=flag) and True or (sre_parse.parse(_p), rr)
示例#8
0
文件: perg.py 项目: anrosent/perg
def parse(s):
    return sre_parse.parse(s)