python - Split string via regular expression -


Suppose I have been given a string like this:

  input = "" " Abc@gmail.com is a very good person xyz@gmail.com is useless lol@gmail.com is very strange. "" ""  

I have a regular expression for an email address : ^ [A-z0-9 \ + \.] + \ @ [A-z0-9 \ + \.] + \. [A-z0-9 \ +] + $

The goal is to split the string based on an email address regular expression:

  [ I am trying to use the  re.split (EMAIL_REGEX, Input), "is a very good person", "is useless", "very strange."]  

but I have not succeeded. I get the output as the full string contained in the list.

^ and $ anchor, as They only match the beginning and end of the string since the email addresses are in the middle of the string, so they never match.

There are other problems in your regexp: Account names can have many other characters compared to those of you, e.g. _ and - . Domain names can have - characters, but not + . And you should not use the A-z range to get upper and lower case characters, because there are letters between two alphabetical blocks that you probably do not want to include (see); Use either A-Za-z or use az and add flags = re.IGNORECASE .


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -