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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 307 views
  • 3 likes
  • 2 in conversation