DATA Step, Macro, Functions and more

Perl regex contraint for replication.

Reply
Contributor
Posts: 67

Perl regex contraint for replication.

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.

Respected Advisor
Posts: 4,549

Re: Perl regex contraint for replication.

[ Edited ]

@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;

 

Esteemed Advisor
Posts: 5,399

Re: Perl regex contraint for replication.

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

PG
Regular Contributor
Posts: 150

Re: Perl regex contraint for replication.

Always check here before doing common regex (IMO):

 

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

 

Regular Contributor
Posts: 153

Re: Perl regex contraint for replication.

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 -

Ask a Question
Discussion stats
  • 4 replies
  • 126 views
  • 1 like
  • 5 in conversation