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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 836 views
  • 1 like
  • 5 in conversation