I want to use re.search to extract the first set of non-whitespace characters. I have the following pseudoscript that recreates my problem:
#!/usr/bin/env python2.7
import re
line = "STARC-1.1.1.5 ConsCase WARNING Warning"
m = re.search('^[^\S]*?',line)
if m:
print m.group(0)
It seems to be printing the whitespace instead of STARC-1.1.1.5
So far as I understand it, this regular expression is saying: At the start of the line, find a set of nonwhitespace characters, don't be greedy
I was pretty sure this would work, the documentation says I can use /S to match whitespace in [], so i'm not sure where the issue is.
Now, I know, I know this probably looks weird, why aren't I using some other function to do this? Well, there's more than one way to skin a cat and i'm still getting the hang of regular expressions in Python so I'd like to know how I can use re.search to extract this field in this fashion.
FutureWarning: split() requires a non-empty pattern match.With\s+I didn't get a warning.\s+didn't trigger a warning inre.py:203.