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 -

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 1062 views
  • 1 like
  • 5 in conversation