You are on page 1of 4

Avem un string: 'abbaaabbbbaaaaa',

Indicati substring-uri care muleaza expresiei date:

'ab*', # a followed by zero or more b

Avem un string: 'abbaaabbbbaaaaa',

Indicati substring-uri care muleaza expresiei date:

'ab+', # a followed by one or more b

Avem un string: 'abbaaabbbbaaaaa',

Indicati substring-uri care muleaza expresiei date:

'ab?', # a followed by zero or one b

Avem un string: 'abbaaabbbbaaaaa',

Indicati substring-uri care muleaza expresiei date:

'ab{3}', # a followed by three b

Avem un string: 'abbaaabbbbaaaaa',

Indicati substring-uri care muleaza expresiei date:

'ab{2,3}', # a followed by two to three b


$ python re_repetition.py

11111
012345678901234
abbaaabbbbaaaaa

Matching "ab*"
0 : 2 = "abb"
3 : 3 = "a"
4 : 4 = "a"
5 : 9 = "abbbb"
10 : 10 = "a"
11 : 11 = "a"
12 : 12 = "a"
13 : 13 = "a"
14 : 14 = "a"

Matching "ab+"
0 : 2 = "abb"
5 : 9 = "abbbb"

Matching "ab?"
0 : 1 = "ab"
3 : 3 = "a"
4 : 4 = "a"
5 : 6 = "ab"
10 : 10 = "a"
11 : 11 = "a"
12 : 12 = "a"
13 : 13 = "a"
14 : 14 = "a"

Matching "ab{3}"
5 : 8 = "abbb"

Matching "ab{2,3}"
0 : 2 = "abb"
5 : 8 = "abbb"
Avem un string: 'This is some text -- with punctuation.',

Indicati substring-uri care muleaza expresiei date:

'[a-z]+'

Avem un string: 'This is some text -- with punctuation.',

Indicati substring-uri care muleaza expresiei date:

'[a-zA-Z]+'

Avem un string: 'This is some text -- with punctuation.',

Indicati substring-uri care muleaza expresiei date:

'[a-z]+'

Avem un string: 'This is some text -- with punctuation.',

Indicati substring-uri care muleaza expresiei date:

'[A-Z]+'

Avem un string: 'This is some text -- with punctuation.',

Indicati substring-uri care muleaza expresiei date:

'[A-Z][a-z]+'
test_patterns('This is some text -- with punctuation.',
[ '[a-z]+', # sequences of lower case
letters
'[A-Z]+', # sequences of upper case
letters
'[a-zA-Z]+', # sequences of lower or
upper case letters
'[A-Z][a-z]+', # one upper case letter
followed by lower case letters
])

https://pymotw.com/2/re/

You might also like