prxmatch, maximum number of matches not working

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

prxmatch, maximum number of matches not working

Why is this 

prxmatch("/^[0-9]{7,8}/", '1234567891011')

returning 1?

 

I need a regular expression with these rules:

  • Variable has to start with a number from 0-9
  • Match at least 7 but not more than 8 times

I m using this sheet: 

https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf


Accepted Solutions
Solution
‎09-19-2016 03:24 AM
Respected Advisor
Posts: 4,814

Re: prxmatch, maximum number of matches not working

The pattern should specify that what follows the 7 or 8 digit number should be a non digit (\D) or the end of string ($)

 

data _null_;
prx = prxParse("/^\d{7,8}(\D|$)/");
do str = '1234567891011', '1234567', '12345678', '1234567_a';
    v = prxmatch(prx, str);
    put str= v=;
    end;
run;
PG

View solution in original post


All Replies
Solution
‎09-19-2016 03:24 AM
Respected Advisor
Posts: 4,814

Re: prxmatch, maximum number of matches not working

The pattern should specify that what follows the 7 or 8 digit number should be a non digit (\D) or the end of string ($)

 

data _null_;
prx = prxParse("/^\d{7,8}(\D|$)/");
do str = '1234567891011', '1234567', '12345678', '1234567_a';
    v = prxmatch(prx, str);
    put str= v=;
    end;
run;
PG
Super User
Posts: 9,867

Re: prxmatch, maximum number of matches not working


data _null_;
x=prxmatch("/^[0-9]{7,8}$/", strip('1234567891011'));
put x=;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 293 views
  • 1 like
  • 3 in conversation