Solved
Contributor
Posts: 50

# 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:

• 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
Posts: 5,529

## 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

All Replies
Solution
‎09-19-2016 03:24 AM
Posts: 5,529

## 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: 10,778

## 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.