Help using Base SAS procedures

Regex prxparse question validating emails

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Regex prxparse question validating emails

Hi

I need some help to understand why this regexpression does not work and the otherone does?

 

Works:

prxparse('/\w[-.\w]*\@[-\w]+(\.[-\w]+)*\.(no|com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|[a-z][a-z])/i')

 

Does not work:

prxparse('/^[a-zA-Z0-9.!#$%&*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/')

 

I try to validate emails using this code replacing the prxparse expression that does not work.

 

%LET Myvariable = TheVariable;
data WORK.OUT;
  re =
  prxparse('/\w[-.\w]*\@[-\w]+(\.[-\w]+)*\.(no|com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|[a-z][a-z])/i');

  do until(eof);
    set _infile_ end=eof;
if ^prxmatch(re,&MyVariable) then do;
      /* appropriate lines of code */
keep &Myvariable;
output;
end;
end;
  run;

 

 

LOG:

SYMBOLGEN:  Macro variable MYREGEXPRESION resolves to
            '/^[a-zA-Z0-9.!#$%&*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a
            -zA-Z0-9])?)*$/'
36           /*prxparse('/\w[-.\w]*\@[-\w]+(\.[-\w]+)*\.(no|com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|[a-z][a-z])/i
36       ! ');*/
37         
38           do until(eof);
             __
             79
ERROR 79-322: Expecting a ;.

 

Your help is much obliged


Accepted Solutions
Solution
‎03-16-2016 05:37 PM
Trusted Advisor
Posts: 1,300

Re: Regex prxparse question validating emails

[ Edited ]

First, the log you posted has an irrelevant syntax error...

 

More importantly, I feel that this is a small bug in the PRX parser where the literal '$' is being confused for a Perl variable reference.  It is, thankfully, also very easy to work-around.

 

The below, I believe, is what you wanted, except fixed to properly comply with the RFC 2822 simplified specification (you had removed the single quotes) and the the '$' characters escaped to avoid the prx parsing error.

 

prxparse('/[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i');

 

data foo;
if _n_=1 then do;
retain prxid;
call prxdebug(1);
prxid=prxparse('/[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i');
call prxdebug(0);
end;

input email : & $400. ;

x=prxmatch(prxid,email);

cards;
president@whitehouse.gov
ip@1.2.3.123
pharaoh@egyptian.museum
john.doe+regexbuddy@gmail.com
Mike.O'Dell@ireland.com
"Mike\ O'Dell"@ireland.com
IPguy@[1.2.3.4]
===
1024x768@60Hz
not.a.valid.email
not@valid.email
john@aol...com
Mike\ O'Dell@ireland.com
;
run;

View solution in original post


All Replies
Solution
‎03-16-2016 05:37 PM
Trusted Advisor
Posts: 1,300

Re: Regex prxparse question validating emails

[ Edited ]

First, the log you posted has an irrelevant syntax error...

 

More importantly, I feel that this is a small bug in the PRX parser where the literal '$' is being confused for a Perl variable reference.  It is, thankfully, also very easy to work-around.

 

The below, I believe, is what you wanted, except fixed to properly comply with the RFC 2822 simplified specification (you had removed the single quotes) and the the '$' characters escaped to avoid the prx parsing error.

 

prxparse('/[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i');

 

data foo;
if _n_=1 then do;
retain prxid;
call prxdebug(1);
prxid=prxparse('/[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i');
call prxdebug(0);
end;

input email : & $400. ;

x=prxmatch(prxid,email);

cards;
president@whitehouse.gov
ip@1.2.3.123
pharaoh@egyptian.museum
john.doe+regexbuddy@gmail.com
Mike.O'Dell@ireland.com
"Mike\ O'Dell"@ireland.com
IPguy@[1.2.3.4]
===
1024x768@60Hz
not.a.valid.email
not@valid.email
john@aol...com
Mike\ O'Dell@ireland.com
;
run;

Occasional Contributor
Posts: 10

Re: Regex prxparse question validating emails

This solution works fine for me.
Thank you very much, this was great help
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 289 views
  • 1 like
  • 2 in conversation