REGEX: how to i get the name more the character " : "
Question:
Im using python to extract some info
i wanna get the words/names before the charcter :
but the problem is everythig is tied together
from here
Morgan Stanley.Erik Woodring:
i just wanna extract "Erik Woodring:"
or from here
market.Operator:
i just wanna extract Operator:
sometimes there are questiosn like this
to acquire?Tim Cook:
i just wanna extract "Tim Cook:"
this is what i tried
w*(?=.*:)
this is not getting what i wanted, its returning a lot of words
Answers:
This could be the regex you’re looking for:
b[ws]+(?=:)
- b world boundary;
- [ws]+ matches any word or whitespace (at least one character);
- (?=:) positive lookahead that specifies the word must be followed by a punctation mark;
https://regex101.com/r/w86oWv/1
If you want to get the ":" too you can simply remove the lookahead:
b[ws]+:
Im using python to extract some info
i wanna get the words/names before the charcter :
but the problem is everythig is tied together
from here
Morgan Stanley.Erik Woodring:
i just wanna extract "Erik Woodring:"
or from here
market.Operator:
i just wanna extract Operator:
sometimes there are questiosn like this
to acquire?Tim Cook:
i just wanna extract "Tim Cook:"
this is what i tried
w*(?=.*:)
this is not getting what i wanted, its returning a lot of words
This could be the regex you’re looking for:
b[ws]+(?=:)
- b world boundary;
- [ws]+ matches any word or whitespace (at least one character);
- (?=:) positive lookahead that specifies the word must be followed by a punctation mark;
https://regex101.com/r/w86oWv/1
If you want to get the ":" too you can simply remove the lookahead:
b[ws]+: