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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Keith
Obsidian | Level 7

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.

View solution in original post

5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12

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

Keith
Obsidian | Level 7

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.

LB
Quartz | Level 8 LB
Quartz | Level 8

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

Keith
Obsidian | Level 7

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'

LB
Quartz | Level 8 LB
Quartz | Level 8

many thanks Keith!

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 836 views
  • 2 likes
  • 3 in conversation