BookmarkSubscribeRSS Feed
Matt3
Quartz | Level 8

Could anyone please tell me how to write perl regex which contains prefix or not + 9 number string which can contain only 5 reps of single number. I can not find constraint for replication.

I use perl regular expression in sas

data regexp;
    if _n_=1 then pattern=prxparse("~^(48|0|48|0048|)+[1-9]{1}+[0-9]{8}~o");    retain pattern;    set new;
    if prxmatch(pattern,nr_tel) then flg=1; else flg=0;run;

Thank you.

4 REPLIES 4
Patrick
Opal | Level 21

@Matt3

Eventually don't try to pack everything into a single RegEx.

Below a RegEx which will find a match for any string with at least 5 repeated digits.

data test;
  infile datalines truncover;
  input string $20.;
  retain prxid;
  if _n_=1 then
    prxid=prxparse('/(\d)\1{4}/');
  check=prxmatch(prxid,string);
  datalines;
1233455556789
1222333334556
1235555555556
;
run;

 

PGStats
Opal | Level 21

Please provide a good sample of match and non-match strings. Try to cover most possibilities.

PG
AlanC
Barite | Level 11

Always check here before doing common regex (IMO):

 

http://www.regexlib.com/?AspxAutoDetectCookieSupport=1

 

https://github.com/savian-net
Oligolas
Barite | Level 11

Hi,

 

you can catch replication by using the lookahead / lookbehind assertions.

We need a bunch of good samples / results to start having fun by helping you.

________________________

- Cheers -

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1492 views
  • 1 like
  • 5 in conversation