Python regular problem

>>> s=""
>>> c=re.findall("(.*)|.*",s)[0]
>>> c
""
>>> c=re.findall("(.*?)|.*",s)[0]
>>> c
""
>>> c=re.findall("(.*)|.*",s)[0]
>>> c
""
>>> c=re.findall("(.*)\|.*",s)[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> c=re.findall("(.*)|.*",s)[0]
>>> c
""
>>> 

Why does it always fail to match the number of words before "|"

Mar.21,2021

matches '|' itself is escaped, because it means "or" in the rule. Also match one or more visible characters with . + . A single . can match only one character.

Menu