Regex is unnecessary for this. Just use some_string.split(' ', 1)[0]
or some_string.partition(' ')[0]
.
More Related Contents:
- Regular expression doesn't produce expected result
- How t extract last part of a text in python [duplicate]
- re.findall behaves weird
- Do regular expressions from the re module support word boundaries (\b)?
- Python extract pattern matches
- Split a string by spaces — preserving quoted substrings — in Python
- Remove all special characters, punctuation and spaces from string
- How to filter rows in pandas by regex
- Natural sorting
- Python regular expression re.match, why this code does not work? [duplicate]
- matching any character including newlines in a Python regex subexpression, not globally
- Python, remove all non-alphabet chars from string
- Python Regex to find a string in double quotes within a string
- Passing a function to re.sub in Python
- Splitting a string with repeated characters into a list
- How to combine multiple regex into single one in python?
- “Nothing to repeat” from Python regex
- Mass string replace in python?
- pandas applying regex to replace values
- Using a RegEx to match IP addresses
- Bug in Python Regex? (re.sub with re.MULTILINE)
- Unexpected NoReverseMatch error when using include() in urls patterns
- Python Regex – How to Get Positions and Values of Matches
- Extract the ‘src’ attribute from an ‘img’ tag using Beautiful Soup
- Matching only a unicode letter in Python re
- Problem with regexp python and sqlite
- How to use str.contains() with multiple expressions in pandas dataframes
- match dates using python regular expressions
- How to Fix JSON Key Values without double-quotes?
- python regular expression across multiple lines