Python Forum
using the reg expression split to get the words
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using the reg expression split to get the words
#3
If you're already using a regex, I'd just grab them all in one go. If match is successful, then all the match objects can be pulled out of the groups() method.
import re
name = "alpha(beta,gamma)"
m = re.match("(\w+)\((\w+),(\w+)\)",name)
print(m.groups())
Output:
('alpha', 'beta', 'gamma')
Reply


Messages In This Thread
RE: using the reg expression split to get the words - by bowlofred - May-10-2020, 06:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression for matching words xinyulon 1 2,266 Mar-09-2022, 10:34 PM
Last Post: snippsat
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 3,004 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Pass results of expression to another expression cmdr_eggplant 2 2,423 Mar-26-2020, 06:59 AM
Last Post: ndc85430
  Read re.split expression NewBeie 2 2,209 Apr-25-2019, 12:12 PM
Last Post: NewBeie
  Compare all words in input() to all words in file Trianne 1 2,869 Oct-05-2018, 06:27 PM
Last Post: ichabod801
  Use regular expression to return 5 words before and after target word. steve1040 2 13,137 Sep-28-2017, 08:45 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020