0
>>>import re    
>>>re.findall(r"[^>]*", "<abc>")
['<abc', '', '']

When i type above code in Python interpreter, i got a weird result.

Why the length of returned list is 3 not 2 ?

yibo wu
  • 1
  • 1
  • 1
    `[^>]*` matches empty locations in front of non-matching chars because `*` matches **0** or more occurrences. – Wiktor Stribiżew Nov 28 '17 at 09:58
  • 1
    `[^>]+` try this – Sanket Nov 28 '17 at 10:01
  • I understand why '+' gives better results, but what empty locations are you referring too? Adjusting the input string to varying lengths still yields an array of three, when I could possibly justify an array of two. >>> re.findall(r"[^>]*", ">> re.findall(r"[^>]*", "") [' – Calvin Taylor Nov 28 '17 at 13:51

0 Answers0