0

So I have a string RAM 1000/2000/3000/4000 and I want to extract RAM 1000, 2000, 3000 and 4000 from it using regular expressions.

So far I've (RAM 1000)(?:(?:\/)(\w+)){1,}, but it returns only RAM 1000 and 4000. How do I get it to return all the desired matches in Python?

1 Answers1

0

While it does seem like str.split would do the job here, if you want to use regular expressions then you probably want to use re.findall:

>>> import re
>>> s = "RAM 1000/2000/3000/4000"
>>> re.findall(r"(?:RAM )?[^/]+", s)
['RAM 1000', '2000', '3000', '4000']
Nolen Royalty
  • 18,415
  • 4
  • 40
  • 50