Hello all-
I am attempting to use a regular expression such as below:
prxparse('/[ N|N| n|n]o.{1,30}infiltrate/i');
For no infiltrate or No infiltrate.
However it is also picking up non xxx infiltrate, normal...infiltrate.
How do I limit it to just no?
I do need the character spaces as there are quite a number of words that can can appear between the two words.
Thank you.
Lawrence
You can simplify your expression to prxparse('/no\b.*infiltrate/i')
The "\b" defines a word boundary, ".*" then matches any number of characters before "infiltrate". You already have "/i" at the end of the expression to ignore case, therefore you don't need to specify "N|N n|n" etc.
Welcome to the world of "natural language processing" (NLP). In specific cases like that I have addressed it with subsequent if-then-else constructs to get at the special cases. You have to do a bit of desk checking and additional review for new special cases when the data are refreshed.
Certainly not ideal, but works OK when the searching is reasonably well contained.
Doc
You can simplify your expression to prxparse('/no\b.*infiltrate/i')
The "\b" defines a word boundary, ".*" then matches any number of characters before "infiltrate". You already have "/i" at the end of the expression to ignore case, therefore you don't need to specify "N|N n|n" etc.
Thanks Keith-That helps immensely-One quick question-what if I do want to set the number of characters as
I don't want to see 'no '500 characters' infiltrate' which is entirely possible. That is why I was containing it to 30 characters.
Lawrence
Then just change .* to .{1,30} in the expression, as per your original post. This will allow up to 30 characters between 'no' and 'infiltrate'
many thanks Keith!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.