Date: Thu, 8 Nov 2007 22:06:39 -0500
Reply-To: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Subject: Re: Regex solution needed.
Yu,
Upon further review, just a negative lookahead will not do. This one should
get the job done. I added more obs to check for robustness.
data test;
if _n_ = 1 then re = prxparse("/\b(\w+(?!')\b)(?<!s)/i");
retain re;
infile cards truncover;
input string $20.;
pos=prxmatch(re, string);
if pos then match = prxposn(re, 1, string);
cards;
john's
book
JOHNS
bike
Jim
James
James'
crayon
;
run;
This regex looks for a 'word', but uses a negative lookahead to assert the
end boundary of the word is not an apostrophe('). Then it uses a negative
lookbehind to assert the last character is not an 's'.
HTH,
Ken
On Thu, 8 Nov 2007 16:54:47 -0600, Yu Zhang <zhangyu05@GMAIL.COM> wrote:
>Hi, Alan,
>
>Thank you for your solution. I didn't make it clear that I want to
>find a word not ending with 's'. the 'john's' is a specical case
>ending with 's', but i can not come up with a correct Regex not
>picking it up.
>
>Thanks!
>
>Yu
>
>On Nov 8, 2007 4:36 PM, Alan Churchill <savian001@gmail.com> wrote:
>> [a-zA-Z']+s
>>
>> Tested using RegexBuddy.
>>
>> Alan
>>
>> Alan Churchill
>> Savian
>> www.savian.net
>>
>>
>>
>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Yu
>> Zhang
>> Sent: Thursday, November 08, 2007 3:19 PM
>> To: SAS-L@LISTSERV.UGA.EDU
>> Subject: Re: Regex solution needed.
>>
>>
>> sorry I posted a wrong testing code. this is what i am tring to show,
>>
>> thanks!
>>
>> Yu
>>
>> data test;
>> if _n_ = 1 then re = prxparse('/\b(\w*(?<!s))\b/');
>>
>> retain re;
>> infile cards truncover;
>> input string $20.;
>>
>> pos=prxmatch(re, string);
>> if pos then match = prxposn(re, 1, string);
>> cards;
>> john's
>> book
>> ;
>> run;
>>
>>
|