当前位置: 首页>>代码示例>>Python>>正文


Python re.VERBOSE属性代码示例

本文整理汇总了Python中re.VERBOSE属性的典型用法代码示例。如果您正苦于以下问题:Python re.VERBOSE属性的具体用法?Python re.VERBOSE怎么用?Python re.VERBOSE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在re的用法示例。


在下文中一共展示了re.VERBOSE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: str2int

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def str2int(string):
  numeric_const_pattern = r"""
  [-+]? # optional sign
  (?:
    (?: \d* \. \d+ ) # .1 .12 .123 etc 9.1 etc 98.1 etc
    |
    (?: \d+ \.? ) # 1. 12. 123. etc 1 12 123 etc
  )
  # followed by optional exponent part if desired
  (?: [Ee] [+-]? \d+ ) ?
  """
  rx = re.compile(numeric_const_pattern, re.VERBOSE)
  nb = rx.findall(string)
  for i in enumerate(nb): nb[i[0]] = int(i[1])
  return np.array(nb)

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 
开发者ID:pyscf,项目名称:pyscf,代码行数:19,代码来源:m_siesta_ion_xml.py

示例2: set_memlimit

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def set_memlimit(limit):
    global max_memuse
    global real_max_memuse
    sizes = {
        'k': 1024,
        'm': _1M,
        'g': _1G,
        't': 1024*_1G,
    }
    m = re.match(r'(\d+(\.\d+)?) (K|M|G|T)b?$', limit,
                 re.IGNORECASE | re.VERBOSE)
    if m is None:
        raise ValueError('Invalid memory limit %r' % (limit,))
    memlimit = int(float(m.group(1)) * sizes[m.group(3).lower()])
    real_max_memuse = memlimit
    if memlimit > MAX_Py_ssize_t:
        memlimit = MAX_Py_ssize_t
    if memlimit < _2G - 1:
        raise ValueError('Memory limit %r too low to be useful' % (limit,))
    max_memuse = memlimit 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:support.py

示例3: str_flags_to_int

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def str_flags_to_int(str_flags):
    flags = 0
    if "i" in str_flags:
        flags |= re.IGNORECASE
    if "l" in str_flags:
        flags |= re.LOCALE
    if "m" in str_flags:
        flags |= re.MULTILINE
    if "s" in str_flags:
        flags |= re.DOTALL
    if "u" in str_flags:
        flags |= re.UNICODE
    if "x" in str_flags:
        flags |= re.VERBOSE

    return flags 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:regex.py

示例4: str2float

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def str2float(string):
  numeric_const_pattern = r"""
  [-+]? # optional sign
  (?:
    (?: \d* \. \d+ ) # .1 .12 .123 etc 9.1 etc 98.1 etc
    |
    (?: \d+ \.? ) # 1. 12. 123. etc 1 12 123 etc
  )
  # followed by optional exponent part if desired
  (?: [Ee] [+-]? \d+ ) ?
  """
  rx = re.compile(numeric_const_pattern, re.VERBOSE)
  nb = rx.findall(string)
  for i in enumerate(nb): nb[i[0]] = float(i[1])

  return np.array(nb) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:m_siesta_ion_xml.py

示例5: _parse

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def _parse(s):
    rx_pattern = re.compile(r"""
        \(CODE .*\)
        |\(ID .*\d\)
    """, re.VERBOSE|re.UNICODE)
    s = re.sub(rx_pattern, '', s)
    s = split(s, '\n')
    fullPhrase = ""
    # loop through the sentences and parse each sentence
    # every time a new sentence marker is found
    for sent in s:
        if list(tokenize.regexp(sent, r'^\(')) != []:
            fullPhrase = _strip_spaces(fullPhrase)               
            if fullPhrase != "":
                yield fullPhrase
            fullPhrase = sent
        else:
            fullPhrase += sent

    # Get the last of the buffer and output a yield
    fullPhrase = _strip_spaces(fullPhrase)
    if fullPhrase != "":
        yield fullPhrase 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:25,代码来源:ycoe.py

示例6: conllesp

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def conllesp():
    from nltk.corpus import conll2002

    de = """
    .*
    (
    de/SP|
    del/SP
    )
    """
    DE = re.compile(de, re.VERBOSE)

    print()
    print("Spanish CoNLL2002: de(ORG, LOC) -- just the first 10 clauses:")
    print("=" * 45)
    rels = [rel for doc in conll2002.chunked_sents('esp.train')
            for rel in extract_rels('ORG', 'LOC', doc, corpus='conll2002', pattern = DE)]
    for r in rels[:10]: print(clause(r, relsym='DE'))
    print() 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:21,代码来源:relextract.py

示例7: is_valid_ip

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def is_valid_ip(addr):
    '''Validate an IPV4 address.

    :param addr: IP address to validate.
    :type addr: ``string``
    :returns: True if is valid else False.
    :rtype: ``bool``
    '''

    ip_rx = re.compile(r'''
        ^(((
              [0-1]\d{2}                  # matches 000-199
            | 2[0-4]\d                    # matches 200-249
            | 25[0-5]                     # matches 250-255
            | \d{1,2}                     # matches 0-9, 00-99
        )\.){3})                          # 3 of the preceding stanzas
        ([0-1]\d{2}|2[0-4]\d|25[0-5]|\d{1,2})$     # final octet
    ''', re.VERBOSE)

    try:
        return ip_rx.match(addr.strip())
    except AttributeError:
        # Value was not a string
        return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:26,代码来源:ip_math.py

示例8: render_re

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def render_re(regex):
  """Renders a repr()-style value for a compiled regular expression."""
  actual_flags = []
  if regex.flags:
    flags = [
      (re.IGNORECASE, 'IGNORECASE'),
      (re.LOCALE, 'LOCALE'),
      (re.UNICODE, 'UNICODE'),
      (re.MULTILINE, 'MULTILINE'),
      (re.DOTALL, 'DOTALL'),
      (re.VERBOSE, 'VERBOSE'),
    ]
    for val, name in flags:
      if regex.flags & val:
        actual_flags.append(name)
  if actual_flags:
    return 're.compile(%r, %s)' % (regex.pattern, '|'.join(actual_flags))
  else:
    return 're.compile(%r)' % regex.pattern 
开发者ID:luci,项目名称:recipes-py,代码行数:21,代码来源:magic_check_fn.py

示例9: __init__

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def __init__(self, spectree):
        super().__init__(spectree)
        from falcon.routing.compiled import _FIELD_PATTERN

        self.FIELD_PATTERN = _FIELD_PATTERN
        # NOTE from `falcon.routing.compiled.CompiledRouterNode`
        self.ESCAPE = r'[\.\(\)\[\]\?\$\*\+\^\|]'
        self.ESCAPE_TO = r'\\\g<0>'
        self.EXTRACT = r'{\2}'
        # NOTE this regex is copied from werkzeug.routing._converter_args_re and
        # modified to support only int args
        self.INT_ARGS = re.compile(r'''
            ((?P<name>\w+)\s*=\s*)?
            (?P<value>\d+)\s*
        ''', re.VERBOSE)
        self.INT_ARGS_NAMES = ('num_digits', 'min', 'max') 
开发者ID:0b01001001,项目名称:spectree,代码行数:18,代码来源:falcon_plugin.py

示例10: test_getstatus

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def test_getstatus(self):
        # This pattern should match 'ls -ld /.' on any posix
        # system, however perversely configured.  Even on systems
        # (e.g., Cygwin) where user and group names can have spaces:
        #     drwxr-xr-x   15 Administ Domain U     4096 Aug 12 12:50 /
        #     drwxr-xr-x   15 Joe User My Group     4096 Aug 12 12:50 /
        # Note that the first case above has a space in the group name
        # while the second one has a space in both names.
        # Special attributes supported:
        #   + = has ACLs
        #   @ = has Mac OS X extended attributes
        #   . = has a SELinux security context
        pat = r'''d.........   # It is a directory.
                  [.+@]?       # It may have special attributes.
                  \s+\d+       # It has some number of links.
                  [^/]*        # Skip user, group, size, and date.
                  /\.          # and end with the name of the file.
               '''

        with check_warnings((".*commands.getstatus.. is deprecated",
                             DeprecationWarning)):
            self.assertTrue(re.match(pat, commands.getstatus("/."), re.VERBOSE)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_commands.py

示例11: remove_stack_traces

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def remove_stack_traces(out):
    # this regexp taken from Python 2.5's doctest
    traceback_re = re.compile(r"""
        # Grab the traceback header.  Different versions of Python have
        # said different things on the first traceback line.
        ^(?P<hdr> Traceback\ \(
            (?: most\ recent\ call\ last
            |   innermost\ last
            ) \) :
        )
        \s* $                   # toss trailing whitespace on the header.
        (?P<stack> .*?)         # don't blink: absorb stuff until...
        ^(?=\w)                 #     a line *starts* with alphanum.
        .*?(?P<exception> \w+ ) # exception name
        (?P<msg> [:\n] .*)      # the rest
        """, re.VERBOSE | re.MULTILINE | re.DOTALL)
    blocks = []
    for block in blankline_separated_blocks(out):
        blocks.append(traceback_re.sub(r"\g<hdr>\n...\n\g<exception>\g<msg>", block))
    return "".join(blocks) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:22,代码来源:plugintest.py

示例12: date_parser

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def date_parser(timestr, parserinfo=None, **kwargs):
    """
    Uses dateutil.parser.parse, but also handles monthly dates of the form
    1999m4, 1999:m4, 1999:mIV, 1999mIV and the same for quarterly data
    with q instead of m. It is not case sensitive. The default for annual
    data is the end of the year, which also differs from dateutil.
    """
    flags = re.IGNORECASE | re.VERBOSE
    if re.search(_q_pattern, timestr, flags):
        y,q = timestr.replace(":","").lower().split('q')
        month, day = _quarter_to_day[q.upper()]
        year = int(y)
    elif re.search(_m_pattern, timestr, flags):
        y,m = timestr.replace(":","").lower().split('m')
        month, day = _month_to_day[m.upper()]
        year = int(y)
        if _is_leap(y) and month == 2:
            day += 1
    elif re.search(_y_pattern, timestr, flags):
        month, day = 12, 31
        year = int(timestr)
    else:
        return to_datetime(timestr, **kwargs)

    return datetime.datetime(year, month, day) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:datetools.py

示例13: _encode_regex

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def _encode_regex(name, value, dummy0, dummy1):
    """Encode a python regex or bson.regex.Regex."""
    flags = value.flags
    # Python 2 common case
    if flags == 0:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"\x00"
    # Python 3 common case
    elif flags == re.UNICODE:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"u\x00"
    else:
        sflags = b""
        if flags & re.IGNORECASE:
            sflags += b"i"
        if flags & re.LOCALE:
            sflags += b"l"
        if flags & re.MULTILINE:
            sflags += b"m"
        if flags & re.DOTALL:
            sflags += b"s"
        if flags & re.UNICODE:
            sflags += b"u"
        if flags & re.VERBOSE:
            sflags += b"x"
        sflags += b"\x00"
        return b"\x0B" + name + _make_c_string_check(value.pattern) + sflags 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:__init__.py

示例14: _split_string

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def _split_string(text):
    """
    Split the combined (decoded) string into left, center and right parts

    # See http://stackoverflow.com/questions/27711175/regex-with-multiple-optional-groups for discussion
    """

    ITEM_REGEX = re.compile("""
    (&L(?P<left>.+?))?
    (&C(?P<center>.+?))?
    (&R(?P<right>.+?))?
    $""", re.VERBOSE | re.DOTALL)

    m = ITEM_REGEX.match(text)
    try:
        parts = m.groupdict()
    except AttributeError:
        warn("""Cannot parse header or footer so it will be ignored""")
        parts = {'left':'', 'right':'', 'center':''}
    return parts 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:header_footer.py

示例15: _parse_regex

# 需要导入模块: import re [as 别名]
# 或者: from re import VERBOSE [as 别名]
def _parse_regex(self, string):
        """Parse output with grouped regex."""
        results = []
        self.regex = re.compile(self.pattern, re.VERBOSE)
        for matches in self.regex.finditer(string):
            results.append(matches.groupdict())
        return results 
开发者ID:ContinuumIO,项目名称:ciocheck,代码行数:9,代码来源:linters.py


注:本文中的re.VERBOSE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。