I'm troubleshooting an awk script that parses a text file. This awk function from the script does not seem to work reliably every time:
Code:
function GetEmail(s) {
res=gensub("^.*[^a-zA-Z0-9._-]([a-zA-Z0-9._-]*@[a-zA-Z0-9.-]*)[^a-zA-Z0-9.-].*$", "\\1", "g", s);
if (res !~ ".*@.*") res="";
return tolower(res);
}
This function is used to extract strings of email addresses. It fails to extract the first email address from
Code:
'members': {'tav@domain.com': 0, 'cclo@domain.com': 0},
I'm guessing that there is a problem with the regex in the functions that makes it not pick up the first address above.
Sometimes it works perfectly, sometimes it misses email addresses. Sometimes the 'members' string is encoded with more than 2 emails in the brackets.
Any advice on why the function seems to sporadically fail would be appreciated.