BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
banksider
Fluorite | Level 6

Suppose that variable x1 has value "123-". That is, x1 = "123-". If I use prxparse("/\ddd-/") and prxmatch I can return position 1 for this value. Now, if I didn't know ("/\ddd-/"), would there be a way for me to obtain ("/\ddd-/")  from  "123-"? That's, is there a way to obtain the perl regular expressions for any entry?

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @banksider,


@banksider wrote:

(...) x1 = "123-". If I use prxparse("/\ddd-/") and prxmatch I can return position 1 for this value.


You mean "/\d\d\d-/", right?


Now, if I didn't know ("/\ddd-/"), would there be a way for me to obtain ("/\ddd-/")  from  "123-"?

The first thing I virtually always do to obtain a regular expression is to open the Tables of Perl Regular Expression (PRX) Metacharacters.


That's, is there a way to obtain the perl regular expressions for any entry?

I don't think there's an automated way to obtain "the" regex for any entry, simply because it is not unique: In your example there is a variety of matching regular expressions (depending on the purpose) ranging from very specific expressions such as "/123-/" to very general expressions like "/.*/". You may want to choose "/\d\d\d-/" for your purposes, but others would prefer, e.g., "/\w{3}?-/" for their purposes.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hello @banksider,


@banksider wrote:

(...) x1 = "123-". If I use prxparse("/\ddd-/") and prxmatch I can return position 1 for this value.


You mean "/\d\d\d-/", right?


Now, if I didn't know ("/\ddd-/"), would there be a way for me to obtain ("/\ddd-/")  from  "123-"?

The first thing I virtually always do to obtain a regular expression is to open the Tables of Perl Regular Expression (PRX) Metacharacters.


That's, is there a way to obtain the perl regular expressions for any entry?

I don't think there's an automated way to obtain "the" regex for any entry, simply because it is not unique: In your example there is a variety of matching regular expressions (depending on the purpose) ranging from very specific expressions such as "/123-/" to very general expressions like "/.*/". You may want to choose "/\d\d\d-/" for your purposes, but others would prefer, e.g., "/\w{3}?-/" for their purposes.

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
  • 1 reply
  • 686 views
  • 3 likes
  • 2 in conversation