-1
date_re = re.compile(r'^stuff (\d\d-\d\d\s)')
date_re.search('stuff 10-18 16:51').group(1)
passt nicht wegen der \s
. Wenn ich das Leerzeichen-Symbol entferne, findet die Gruppe das xx-xx-Ziffernmuster in Ordnung. Was mache ich falsch mit dem Platz in der Regex?Python Regex nicht mit Whitespace innerhalb der Erfassungsgruppe
Mein vollständiger Code:
>>> print t
stuff 11-16 12:10, Size 1.64 GiB, ULed by
>>>date_long_re = re.compile(r'^stuff (\d\d-\d\d\s\d\d\d\d)')
>>>size_re = re.compile(r'Size \d+[.\d*]?')
>>>date_re = re.compile(r'^stuff (\d\d-\d\d\s)')
>>>date_re.search(t).group(1)
AttributeErrorTraceback (most recent call last)
<ipython-input-10-18bd3a48937c> in <module>()
3 size_re = re.compile(r'Size \d+[.\d*]?')
4 date_re = re.compile(r'^stuff(\d\d-\d\d\s)')
----> 5 date_re.search(t).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
[Ich kann nicht repro] (https://ideone.com/AUqNcV). –
Was ist in 'Zeug'? – Jan
stuff ist ein String-Literal. Ich kann auch nicht in diesem Web-Intrepreter reproduzieren, auch nicht bei meinem lokalen Dolmetscher. Ich benutze die Anaconda Jupyter Distribution und es passiert nur in diesem, aber ich komme nicht um es .... – user1561108