Help using Base SAS procedures

reg expressions part II-controlling the "no" in the expression

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 133
Accepted Solution

reg expressions part II-controlling the "no" in the expression

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


Accepted Solutions
Solution
‎07-23-2012 12:08 PM
Regular Contributor
Posts: 151

Re: reg expressions part II-controlling the "no" in the expression

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


All Replies
Valued Guide
Posts: 2,108

Re: reg expressions part II-controlling the "no" in the expression

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

Solution
‎07-23-2012 12:08 PM
Regular Contributor
Posts: 151

Re: reg expressions part II-controlling the "no" in the expression

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.

Frequent Contributor
Frequent Contributor
Posts: 133

Re: reg expressions part II-controlling the "no" in the expression

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

Regular Contributor
Posts: 151

Re: reg expressions part II-controlling the "no" in the expression

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'

Frequent Contributor
Frequent Contributor
Posts: 133

Re: reg expressions part II-controlling the "no" in the expression

many thanks Keith!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 173 views
  • 2 likes
  • 3 in conversation