BookmarkSubscribeRSS Feed
Satish_Parida
Lapis Lazuli | Level 10

Hi Experts,

 

some of the praxmatch are not working for some regular expressions. 

 

Could you please tell me whats wrong with the regular expressions where it is not working.

 

data test;
input StudyEventKey:$40.;
x = prxmatch(prxparse('/^VIST\[*\]*V*\[*\]/') ,StudyEventKey);	/*Does not work*/
x1 = prxmatch(prxparse('/^VIST\[*\]*V*\[1\]/') ,StudyEventKey);
x2 = prxmatch(prxparse('/^VIST\[*\]*V*\[2\]/') ,StudyEventKey);
y = prxmatch(prxparse('/^VIST\[*\]*V*/') ,StudyEventKey);
z = prxmatch(prxparse('/^VIST\[*\]\/*V*\[*\]/') ,StudyEventKey);  /*Does not work*/
cards;
VIST[1]/FV[1]
VIST[1]/SV[1]
VIST[1]/TV[1]
VIST[2]/FV[1]
VIST[2]/SV[1]
VIST[2]/TV[1]
;
run;
6 REPLIES 6
Criptic
Lapis Lazuli | Level 10

Hey @Satish_Parida 

 

The First Statement doesn't work because you are looking for the word VISIT then for 0 to n occurences of [ that is probabely not the intended effect.

 

Something like ^VIST\[\d\]*V*\[*\] would to the trick here.

 

I highly recommend using https://regexr.com/38ed7 to built your regex.

 

Kind regards

Criptic

Satish_Parida
Lapis Lazuli | Level 10
Thank you, but x1 and x2 give correct output, that's why I am confused what is wrong with x?
Criptic
Lapis Lazuli | Level 10
x1 findes the string VISIT[1] - why? because you match VISIT from the beginning, then 0 to n [, 0 to n ], 0 to n V, [, a 1 and finally a ] - so this regex finds the string VISIT[1] so this seems to work but it really doesn't do what you want.

x2 works in the same way, except that it matches VISIT[2]
Satish_Parida
Lapis Lazuli | Level 10
Thank you.

Expression: /^VIST\[*[0-9|A-Z]\]\/*[0-9|A-Z]V\[*[0-9|A-Z]\]$/ works for all the scenarios I have.

Could you please help me with the expression, which will work for the following.

VIST[1A]/SSV[10A]
Criptic
Lapis Lazuli | Level 10
^VIST\[[-zA-Z0-9]*\]\/SSV\[[a-zA-Z0-9]*\]$
Satish_Parida
Lapis Lazuli | Level 10
This is a huge domain and I am new to REGEX,

/^VIST\[\w*\]\/\w*V\[\w*]$/

This is the best I could find.

Thank you for all your input.

The website https://regexr.com/38ed7 is very helpful.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 997 views
  • 2 likes
  • 2 in conversation