0
in python what would be matched by "(4{5,6})\1"?
explain
5 odpowiedzi
+ 4
Looks like a regular expression.
(4{5,6}) is a 4 that is repeated five or six times. The whole expression is a capturing group because of the parentheses
\1 is one repetition of the first capturing group.
So the expression would match 4444444444 or 444444444444 (=10 or 12 times '4')
+ 4
Actually, I'd expect it to find matches in *all* strings which have at least 10 consecutive 4s.
In order for the capturing group to be repeated, there should be at least ten 4s present, but not necessarily *exactly* tens or twelves of those.
For example, if you have a string containing 16 or 23 4s -- it will also match.
+ 4
I'd say that depends on the regex method that is used.
import re
ptrn = re.compile(r'(4{5,6})\1')
s = '807654354444444444123456djs'
print(ptrn.search(s))
# <_sre.SRE_Match object; span=(8, 18), match='4444444444'>
print(ptrn.match(s))
# None
s = '444444444444444444444444444444444'
print(ptrn.search(s))
# <_sre.SRE_Match object; span=(0, 12), match='444444444444'>
print(ptrn.match(s))
# <_sre.SRE_Match object; span=(0, 12), match='444444444444'>
for t in ptrn.finditer(s):
print('>>>', t)
# >>> <_sre.SRE_Match object; span=(0, 12), match='444444444444'>
# >>> <_sre.SRE_Match object; span=(12, 24), match='444444444444'>
+ 4
Anna A-greedy ;)
+ 2
10 or 12 fours