In Python, re.split("\W+", "fat-free milk") yields ['fat', 'free', 'milk'].
How do I produce ['fat-free', 'milk'] from re.split()?
I understand the problem to be that hyphens are not alphanumeric characters, but I’m not sure how to incorporate this fact into the regex. I have tried re.split("[(^\-)\W]+", "fat-free milk") to no avail.
1 Answer