0

I got something that works for one match but not two. I have to find any text such as "account" or "customer" in a file header. It could be one, both, or none. I have headers of a .csv (tab separated) like this:

test_header = apple   orange  account  customer

then I do

match = re.match(".*(account)|(customer).*", test_header, re.IGNORECASE)

The match is finding match.group(1) as "account", but I when I print match.group(2), it returns "None".

What am I missing? I've looked at other similar examples here but not finding what's wrong.

Chuck
  • 1,061
  • 1
  • 20
  • 45

1 Answers1

1

Use re.findall():

import re


test_header = 'apple   orange  account  customer'
match = re.findall(r"account|customer", test_header, re.IGNORECASE)

print(match)

Output:

['account', 'customer']
Terry Spotts
  • 3,527
  • 1
  • 8
  • 21