excel - RegEx to extract email -


i need extract email spreadsheet in excel. i've found example vb code here on stackoverflow link, courtesy of portland runner.

i created excel module , seems working fine, except. return first uppercase character of address in cell , ignoring email.

for example:

text                                    | result ----------------------------------------|------------------------------ email address address@gmail.com   | email address   yes  address@gmail.com                  | yes  

below code i'm using:

function simplecellregex(myrange range) string     dim regex new regexp     dim strpattern string     dim strinput string     dim strreplace string     dim stroutput string       strpattern = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"      if strpattern <> ""         strinput = myrange.value         strreplace = ""          regex             .global = true             .multiline = true             .ignorecase = false             .pattern = strpattern         end          if regex.test(strinput)             simplecellregex = regex.replace(strinput, strreplace)         else             simplecellregex = "not matched"         end if     end if end function 

i not have enough experience vb diagnose might happening here, able spot i'm doing wrong.

working code

function simplecellregex(myrange range) string dim regex new regexp dim strpattern string dim strinput string dim strreplace string dim stroutput string   strpattern = "[a-za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-za-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"  if strpattern <> ""     strinput = myrange.value     strreplace = ""      regex         .global = true         .multiline = true         .ignorecase = true         .pattern = strpattern     end      if regex.test(strinput)         set matches = regex.execute(strinput)         simplecellregex = matches(0).value     else         simplecellregex = "not matched"     end if end if end function 

when return strinput same string input. need return value has been found using regexp.

try

set matches = regex.execute(strinput) simplecellregex = matches(1).value 

instead of

simplecellregex = regex.replace(strinput, strreplace) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -