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

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!

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