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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.