Get sentence after pattern with regex python -


in string (example adopted this turorial) want until first following . after generic (year). pattern:

str = 'purple alice@google.com, (2002).blah monkey. (1991).@abc.com blah dishwasher' 

i think i'm there code not quite yet:

test = re.findall(r'[\(\d\d\d\d\).-]+([^.]*)', str) 

... returns: ['com, (2002)', 'blah monkey', ' (1991)', '@abc', 'com blah dishwasher']

the desired output is:

['blah monkey', '@abc']

in other words, want find between year pattern , next dot.

if want every thing between (year). , first . can use this:

\(\d{4}\)\.([^.]*) 

see live demo.

and explanation here:

"\(\d{4}\)\.([^.]*)"g  \( matches character ( literally   \d{4} match digit [0-9]     quantifier: {4} 4 times        \) matches character ) literally          \. matches character . literally 1st capturing group ([^.]*)     [^.]* match single character not present in list below         quantifier: * between 0 , unlimited times, many times possible, giving needed [greedy]         . literal character . g modifier: global. matches (don't return on first match) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -