コード例 #1
0
from re_test_patterns_groups import test_patterns
"""
    (a)+ 与 (a+) 对于 aaaa 来说是不一样的:
    (a)+, groups() -> a,
    (a+), groups() -> aaaa
"""
test_patterns(
    'abbaabbba',
    [
        (r'a((a+)|(b+))',
         'a then seq. of a or seq. of b'),  # 没有匹配则为None,而不是为空字符串
        (r'a((a|b)+)', 'a then seq. of [ab]')
    ],
)
def main():
    test_patterns("abbaabbba",
                  [(r"a((a*)(b*))", "a followed by 0-n a and 0-n b")])
コード例 #3
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from re_test_patterns_groups import test_patterns

test_patterns("abbaaabbbbaaaaa", [r"a((a+)|(b+))", r"a((?:a+)|(?:b+))"])  # forma capturing  # forma non-capturing
コード例 #4
0
from re_test_patterns_groups import test_patterns

test_patterns('abbaabbba', [(r'a((a*)(b*))', 'a fllowed by 0-n a and 0-n b')])
コード例 #5
0
ファイル: re_groups_nested.py プロジェクト: xbee/pymotw
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Nested groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaaabbbbaaaaa',
    [
        r'a((a*)(b*))',  # 'a' followed by 0-n 'a' and 0-n 'b'
    ])
コード例 #6
0
"""

#end_pymotw_header
import re

from re_test_patterns_groups import test_patterns

# 'a((a|b)+)' (a then seq. of [ab])
#
# 'abbaabbba'
# 'abbaabbba'  ('bbaabbba', 'a')
#  the outer group is `bbaabbba`, then find (a|b) - the first inner group in it, so it matches single a or b, whichever is the LAST
#  character in the string. Only the last match is accessible
test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'a then seq. of a or seq. of b'),
     (r'a((a|b)+)', 'a then seq. of [ab]'),
     (r'a([ab]+)', 'a then seq. of [ab]'),],
)

print('------------------')


# the group is the last character matched in the pattern
test_patterns(
    'bcaabc',
    [(r'(a|b|c)+', 'seq. of [ab]'),
     (r'([abc])+', 'seq. of [ab]'),]
)

# https://docs.python.org/3/library/re.html
# If a group matches multiple times, only the last match is accessible:
コード例 #7
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Matching alternative groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns('abbaaabbbbaaaaa',
              [r'a((a+)|(b+))', # 'a' followed by a sequence of 'a' or sequence of 'b'
               r'a((a|b)+)',    # 'a' followed by a sequence of 'a' or 'b'
               ])
コード例 #8
0
ファイル: re_groups_nested.py プロジェクト: playbar/pylearn
# re_groups_nested.py

from re_test_patterns_groups import test_patterns;

test_patterns(
    'abbaabbba',
    [(r'a((a*)(b*))', 'a followed by 0-n a and 0-n b')],
)

# re_groups_alternative.py

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'a then seq. of a or seq. of b'),
     (r'a((a|b)+)', 'a then seq. of [ab]')],
)


# re_groups_noncapturing.py

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'capturing form'),
     (r'a((?:a+)|(?:b+))', 'noncapturing')],
)

コード例 #9
0
# re_groups_noncapturing.py

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'forma catturante'),
     (r'a((?:a+)|(?:b+))', 'non catturante')],
)
コード例 #10
0
#!/usr/bin/env python3
# encoding: utf-8

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'capturing form'),
     (r'a((?:a+)|(?:b+))', 'noncapturing')],
)
コード例 #11
0
# re_groups_alternative.py

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'a poi sequenza di a o sequenza di b'),
     (r'a((a|b)+)', 'a poi sequenza di [ab]')],
)
コード例 #12
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Non-capturing groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaaabbbbaaaaa',
    [
        r'a((a+)|(b+))',  # capturing form
        r'a((?:a+)|(?:b+))',  # non-capturing
    ])
コード例 #13
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Non-capturing groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns('abbaaabbbbaaaaa',
              [(r'a((a+)|(b+))',     "capturing form"),
               (r'a((?:a+)|(?:b+))', "non-capturing"),
               ])
コード例 #14
0
# re_groups_nested.py

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a*)(b*))', 'a seguita da 0-n a e 0-n b')],
)
コード例 #15
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Matching alternative groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaaabbbbaaaaa',
    [
        r'a((a+)|(b+))',  # 'a' followed by a sequence of 'a' or sequence of 'b'
        r'a((a|b)+)',  # 'a' followed by a sequence of 'a' or 'b'
    ])
コード例 #16
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from re_test_patterns_groups import test_patterns

test_patterns('abbaaabbbbaaaaa',
              [r'a((a+)|(b+))', # 'a' seguito da una sequanza di 'a' o da una sequenza di 'b'
               r'a((a|b)+)',    # 'a' seguito da una sequenza di 'a' o 'b'
               ])
コード例 #17
0
def main():
    test_patterns("abbaabbba", [(r"a((a+)|(b+))", "capturing form"),
                                (r"a((?:a+)|(?:b+))", "noncapturing")])
コード例 #18
0
#!/usr/bin/env python3
# encoding: utf-8

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'a then seq. of a or seq. of b'),
     (r'a((a|b)+)', 'a then seq. of [ab]')],
)
コード例 #19
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Non-capturing groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns('abbaaabbbbaaaaa', [
    (r'a((a+)|(b+))', "capturing form"),
    (r'a((?:a+)|(?:b+))', "non-capturing"),
])
# re_groups_nested.py
from re_test_patterns_groups import test_patterns

test_patterns("abbaabbba", [(r"a((a*)(b*))", "a folloewd by 0-n a and 0-n b")])
コード例 #21
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Matching alternative groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [ (r'a((a+)|(b+))', 'a then seq. of a or seq. of b'),
      (r'a((a|b)+)', 'a then seq. of [ab]'),
     ])
コード例 #22
0
#!/usr/bin/env python3
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Noncapturing groups
"""

#end_pymotw_header
from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [(r'a((a+)|(b+))', 'capturing form'),
     (r'a((?:a+)|(?:b+))', 'noncapturing')],
)
コード例 #23
0
# re_groups_alternative.py

from re_test_patterns_groups import test_patterns

test_patterns("abbaabbba", [(r"a((a+)|(b+))", "a then seq. of a or ser. of b"),
(r"a((a|b)+)", "a then seq. of [ab]")])
コード例 #24
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Nested groups
"""
# end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns("abbaaabbbbaaaaa", [r"a((a*)(b*))"])  # 'a' followed by 0-n 'a' and 0-n 'b'
コード例 #25
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from re_test_patterns_groups import test_patterns

test_patterns('abbaaabbbbaaaaa',
              [r'a((a*)(b*))', # 'a' seguito da 0-n 'a' e 0-n 'b'
               ])
コード例 #26
0
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Nested groups
"""
#end_pymotw_header

from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    [ (r'a((a*)(b*))', 'a followed by 0-n a and 0-n b'),
     ])
コード例 #27
0
ファイル: re_groups_nested.py プロジェクト: robyy/pymotw-3
#!/usr/bin/env python3
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Nested groups
"""

#end_pymotw_header
from re_test_patterns_groups import test_patterns

test_patterns(
    'abbaabbba',
    # if nested groups, starting from most outer group, then inner groups left to right
    [(r'a((a*)(b*))', 'a followed by 0-n a and 0-n b')],
)