BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

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

2 REPLIES 2
FriedEgg
SAS Employee

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;

sveinola_gundhus_tv2_no
Fluorite | Level 6
This solution works fine for me.
Thank you very much, this was great help

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 4187 views
  • 2 likes
  • 2 in conversation