- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am new to regular expression and feel lost when I try to understand the pattern that are described in this format.
I see a follwoing codes and could not understand what they means. Could anyone guide me on this?Thanks.
footnote( _n_ ) ne " "
and prxmatch( "/^'\s*'$/" , strip( footnote( _n_ ))) = 0
and prxmatch( '/^"\s*"$/' , strip( footnote( _n_ ))) = 0
and resolve( footnote( _n_ )) ne " "
and prxmatch( "/^'\s*'$/" , strip( resolve( footnote( _n_ )))) = 0
and prxmatch( '/^"\s*"$/' , strip( resolve( footnote( _n_ )))) = 0
what "prxmatch( "/^'\s*'$/" , strip( footnote( _n_ ))) = 0" mean?
whether it is same as " prxmatch( '/^"\s*"$/' , strip( footnote( _n_ ))) = 0"?
why we need "resolve( footnote( _n_ )) ne " "" and then repeat prxmatch process?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to pass the RegEx as a string to the SAS RegEx function. That's why you need the outer quotes. The can be single or double quotes.
"/^'\s*'$/"
To not get into some complicated masking exercise the inner quotes must just be different from the outer quotes (if outer single then inner double and vise versa).
The inner quotes are now just part of the Regular Expression - which I assume is not what the developer intended to do.
The RegEx is: ^'\s*'$
^ Beginning of string
' the single quote character
\s a non-printable character ,
* zero, one or many occurrences of the previous character -> zero, one or many non-printable characters
' the single quote character
$ end of string
Above RegEx will find a match if the source string only contains zero, one or multiple non-print characters that are embedded into single quotes. If there is any other character in the string then it won't be a match (because of ^'...'$).
Because SAS is padding character variables with blanks what's also really important is to use trim() or strip() around the source variable to search.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
refer to the documentation.https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2ref/p0m49np18q0pdxn1laab98pazajo.htm
It will return 0 if no match is found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you know what "/^'\s*'$/" means? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I updated the link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://support.sas.com/resources/papers/proceedings20/5172-2020.pdf this paper will go over a lot of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@stataq This syntax doesn't look right to start with because of the quoting.
SAS functions that start with prx.. like prxmatch() allow to use Perl Regular Expressions within SAS code.
Regular Expressions can be very powerful for working with text patterns.
Learning the Perl Regular Expression syntax will take you a bit of time. Others already shared links with you to get into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the input.
Do you mean two ' in "/^'\s*'$/" should not be allowed? I did have difficulty understand why there are ' ' in the code and the next line they have " ". In my mind, even the first one is correct, ''="" in most of the place, why there are two lines? what is the benefit to do repeat this process on resolve( footnote( _n_ ))?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to pass the RegEx as a string to the SAS RegEx function. That's why you need the outer quotes. The can be single or double quotes.
"/^'\s*'$/"
To not get into some complicated masking exercise the inner quotes must just be different from the outer quotes (if outer single then inner double and vise versa).
The inner quotes are now just part of the Regular Expression - which I assume is not what the developer intended to do.
The RegEx is: ^'\s*'$
^ Beginning of string
' the single quote character
\s a non-printable character ,
* zero, one or many occurrences of the previous character -> zero, one or many non-printable characters
' the single quote character
$ end of string
Above RegEx will find a match if the source string only contains zero, one or multiple non-print characters that are embedded into single quotes. If there is any other character in the string then it won't be a match (because of ^'...'$).
Because SAS is padding character variables with blanks what's also really important is to use trim() or strip() around the source variable to search.