本文整理汇总了Python中re_test_patterns.test_patterns函数的典型用法代码示例。如果您正苦于以下问题:Python test_patterns函数的具体用法?Python test_patterns怎么用?Python test_patterns使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了test_patterns函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_patterns
# -*- coding: utf-8 -*-
"""贪婪匹配"""
from re_test_patterns import test_patterns
test_patterns('abbaaabbbbaaaaa',
['ab*',
'ab+',
'ab?',
'ab{3}',
'ab{2,3}'])
示例2: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Escaping escape codes
"""
#end_pymotw_header
from re_test_patterns import test_patterns
test_patterns(r'\d+ \D+ \s+ \S+ \w+ \W+',
[ r'\\d\+',
r'\\D\+',
r'\\s\+',
r'\\S\+',
r'\\w\+',
r'\\W\+',
])
示例3: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Regular expression grouping
"""
#end_pymotw_header
from re_test_patterns import test_patterns
test_patterns(
'abbaaabbbbaaaaa',
[ ('a(ab)', 'a followed by literal ab'),
('a(a*b*)', 'a followed by 0-n a and 0-n b'),
('a(ab)*', 'a followed by 0-n ab'),
('a(ab)+', 'a followed by 1-n ab'),
])
示例4: test_patterns
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from re_test_patterns import test_patterns
test_patterns(
"abbaaabbbbaaaaa",
[
"ab*", # a seguito da zero o più b
"ab+", # a seguito da uno o più b
"ab?", # a seguito da zero od una b
"ab{3}", # a seguito da tre b
"ab{2,3}", # a seguito da due a tre b
],
)
示例5: test_patterns
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from re_test_patterns import test_patterns
test_patterns('abbaaabbbbaaaaa',
[ 'a(ab)', # 'a' seguito da 'ab' letterale
'a(a*b*)', # 'a' seguito da 0-n 'a' e 0-n 'b'
'a(ab)*', # 'a' seguito da 0-n 'ab'
'a(ab)+', # 'a' seguito da 1-n 'ab'
])
示例6: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Escape codes
"""
# end_pymotw_header
from re_test_patterns import test_patterns
test_patterns(
"A prime #1 example!",
[
(r"\d+", "sequence of digits"),
(r"\D+", "sequence of nondigits"),
(r"\s+", "sequence of whitespace"),
(r"\S+", "sequence of nonwhitespace"),
(r"\w+", "alphanumeric characters"),
(r"\W+", "nonalphanumeric"),
],
)
示例7: test_patterns
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from re_test_patterns import test_patterns
test_patterns('abbaaabbbbaaaaa',
[ 'a.', # a seguito da qualsiasi carattere
'b.', # b seguito da qualsiasi carattere
'a.*b', # a seguito da qualunque cosa, che finisca per b
'a.*?b', # a seguito da qualunque cosa, che finisca per b
])
示例8: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Escape codes
"""
#end_pymotw_header
from re_test_patterns import test_patterns
test_patterns('This is a prime #1 example!',
[ r'\d+', # sequence of digits
r'\D+', # sequence of non-digits
r'\s+', # sequence of whitespace
r'\S+', # sequence of non-whitespace
r'\w+', # alphanumeric characters
r'\W+', # non-alphanumeric
])
示例9: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Repetition of patterns
"""
#end_pymotw_header
from re_test_patterns import test_patterns
test_patterns(
'This is some text -- with punctuation.',
[ ('[^-. ]+', 'sequences without -, ., or space'),
])
示例10: test_patterns
# re_anchoring.py
from re_test_patterns import test_patterns
test_patterns(
'Trova in parte di testo -- con punteggiatura.',
[(r'^\w+', 'parola ad inizio stringa'),
(r'\A\w+', 'parola ad inizio stringa'),
(r'\w+\S*$', 'parola verso la fine della stringa, senza punteggiatura'),
(r'\w+\S*\Z', 'parola verso la fine della stringa, senza punteggiatura'),
(r'\w*t\w*', 'parola che contiene t'),
(r'\bt\w+', 't ad inizio della parola'),
(r'\w+t\b', 't alla fine della parola'),
(r'\Bt\B', 't, non all\'inizio o fine della parola')],
)
示例11: test_patterns
# re_repetition_non_greedy.py
from re_test_patterns import test_patterns
test_patterns(
'abbaabbba',
[('ab*?', 'a seguito da zero o più b'),
('ab+?', 'a seguito da one o più b'),
('ab??', 'a seguito da zero od una b'),
('ab{3}?', 'a seguito da tre b'),
('ab{2,3}?', 'a seguito da due fino a tre b')],
)
示例12: test_patterns
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from re_test_patterns import test_patterns
test_patterns('Questa porzione di testo -- con punteggiatura.',
[ '[a-z]+', # sequenza di lettere minuscole
'[A-Z]+', # sequenza di lettere maiuscole
'[a-zA-Z]+', # sequenza di lettere maiuscole o minuscole
'[A-Z][a-z]+', # una lettera maiuscola seguita da lettere minuscole
])
示例13: test_patterns
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Repetition of patterns
"""
from re_test_patterns import test_patterns
test_patterns(
'abbaabbba',
[ ('[ab]', 'either a or b'),
('a[ab]+', 'a followed by 1 or more a or b'),
('a[ab]+?', 'a followed by 1 or more a or b, not greedy'),
]
)
示例14: test_patterns
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from re_test_patterns import test_patterns
test_patterns('abbaaabbbbaaaaa',
[ '[ab]', # sia a che b
'a[ab]+', # a seguito da uno o più a oppure b
'a[ab]+?', # a seguito da uno o più a oppure b, non greedy
])
示例15: Copyright
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Repetition of patterns
"""
#end_pymotw_header
from re_test_patterns import test_patterns
test_patterns(
'This is some text -- with punctuation.',
[ ('[a-z]+', 'sequences of lowercase letters'),
('[A-Z]+', 'sequences of uppercase letters'),
('[a-zA-Z]+', 'sequences of lowercase or uppercase letters'),
('[A-Z][a-z]+', 'one uppercase followed by lowercase'),
])