<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: find a phrase between two words using RE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557717#M155527</link>
    <description>&lt;P&gt;Apologies, I misunderstood you were looking for Terms between the words reporting and Information.&lt;/P&gt;&lt;P&gt;Here is the updated code (please note that regex are case sensitive):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length a $500;
a="some text here

reporting: by Mr. Jones

new 'left home' was selected

information:
the new home was found 
Tasks:
provide information about 'left home8'
Tasks:
provide information about 'left home8'
";
run;

data want;
   length replace1 property replace2 variant $500;
   set have;

   pattern1=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$1XXX$3/');
   pattern2=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$2/');*# same as before only capturing the second group that is left home;
   /*
   (.*(?&amp;lt;=reporting:).*)  # Any text followed by reporting: (as positive lookbehind assertion) followed by any text
             (left home)  # The text to search: left home
   (.*(?=information:).*) # Any text followed by information: (as positive lookahead assertion) followed by any text 
   /$1XXX$3/              # the replacement string: first capturing group, followed by XXX instead of left home, followed by the rest of the text
   */
   replace1=prxchange(pattern1,-1,a);
   property=prxchange(pattern2,-1,a);

   pattern3=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home(10|\d))(.*)/$1YYY$3/');
   pattern4=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home(10|\d))(.*)/$2/');*# same as before only capturing the second group that is left home with specified digits;
   /*
   (.*(?&amp;lt;=Tasks:).*)      # Any text followed by Tasks: (as positive lookbehind assertion) followed by any text 
   (left home(10|\d))     # The text to search: left home, followed by 10 or any digit
   (.*)                   # Any text
   /$1YYY$3/              # the replacement string: first capturing group, followed by YYY instead of left home with specified digits, followed by any text in the 3rd capturing group
   */
   replace2=prxchange(pattern3,-1,a);
   variant=prxchange(pattern4,-1,a);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2019 09:49:32 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2019-05-10T09:49:32Z</dc:date>
    <item>
      <title>find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557401#M155389</link>
      <description>&lt;P&gt;Hi all; I would like you assist me with this exercise:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to :&lt;BR /&gt;1) find a phrase '&lt;CODE class=" language-sas"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;left home'&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/CODE&gt;&amp;nbsp;(&lt;FONT color="#FF0000"&gt;in red)&lt;/FONT&gt;&amp;nbsp; &lt;U&gt;between&lt;/U&gt; 2 words&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt; &lt;CODE class=" language-sas"&gt;(reporting: and&amp;nbsp;information:)&amp;nbsp;&lt;/CODE&gt;in blue&lt;/FONT&gt;&lt;/STRONG&gt; and assign a value to variable &lt;U&gt;&lt;STRONG&gt;property&lt;/STRONG&gt; &lt;/U&gt;= left home:&lt;/P&gt;&lt;P&gt;2) find a phrase '&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;left home8' (&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/CODE&gt;&lt;FONT color="#800080"&gt;&lt;STRONG&gt;in purple)&lt;/STRONG&gt; &lt;FONT color="#000000"&gt;&lt;U&gt;after&lt;/U&gt; the word&lt;/FONT&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;Tasks: (in green)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#008000"&gt;&lt;FONT color="#000000"&gt; and asign value to variable &lt;U&gt;&lt;STRONG&gt;variant&lt;/STRONG&gt;&lt;/U&gt;=left0-10 ( the number after left home could be either 0-10, so need to do that in one rule and not 10...)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;BR /&gt;here is the text :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;some text here

&lt;FONT color="#0000FF"&gt;reporting:&lt;/FONT&gt; by Mr. Jones

new '&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;left home'&lt;/STRONG&gt;&lt;/FONT&gt; was selected

&lt;FONT color="#0000FF"&gt;information:&lt;/FONT&gt;
the new home was found 

&lt;STRONG&gt;&lt;FONT color="#008000"&gt;Tasks:&lt;/FONT&gt;&lt;/STRONG&gt;
provide information about '&lt;STRONG&gt;&lt;FONT color="#800080"&gt;left home8'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you for your support.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 10:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557401#M155389</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-09T10:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557402#M155390</link>
      <description>&lt;P&gt;EDITED: sorry the forum don"t allow proper formating of colors... so the color hints are not working...&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 10:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557402#M155390</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-09T10:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557440#M155399</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length a $500;
a="some text here

reporting: by Mr. Jones

new 'left home' was selected

information:
the new home was found 
Tasks:
provide information about 'left home8'
";
run;

data want;
   length replace1 property replace2 variant $500;
   set have;
   pattern1="s/(\b\w+\b\s+\W)(left home)(\W?\s+\b\w+\b)/$1XXX$3/";
   replace1=prxchange(pattern1,-1,a);
   property=prxchange("s/(.*\b\w+\b\s+\W)(left home)(\W?\s+\b\w+\b.*)/$2/",-1,a);

   pattern2="s/(.*Tasks:.*)(left home\d{1,2})(.*)/$1YYY$3/";
   replace2=prxchange(pattern2,-1,a);
   variant=prxchange("s/(.*Tasks:.*)(left home(10|\d))(\W?.*)/$2/",-1,a);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 13:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557440#M155399</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-05-09T13:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557446#M155400</link>
      <description>&lt;P&gt;Thank you very much for your answer, could you precise how to use the exact words I have mentionned ? because I need to start searching between these words ( and after in the case of Tasks: )&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;reporting:&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(and the ending word)&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;information:&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and also the word after which the program will scan for information ?&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;tasks:&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for this.&lt;BR /&gt;&lt;BR /&gt;Sincerely.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 14:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557446#M155400</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-09T14:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557717#M155527</link>
      <description>&lt;P&gt;Apologies, I misunderstood you were looking for Terms between the words reporting and Information.&lt;/P&gt;&lt;P&gt;Here is the updated code (please note that regex are case sensitive):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length a $500;
a="some text here

reporting: by Mr. Jones

new 'left home' was selected

information:
the new home was found 
Tasks:
provide information about 'left home8'
Tasks:
provide information about 'left home8'
";
run;

data want;
   length replace1 property replace2 variant $500;
   set have;

   pattern1=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$1XXX$3/');
   pattern2=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$2/');*# same as before only capturing the second group that is left home;
   /*
   (.*(?&amp;lt;=reporting:).*)  # Any text followed by reporting: (as positive lookbehind assertion) followed by any text
             (left home)  # The text to search: left home
   (.*(?=information:).*) # Any text followed by information: (as positive lookahead assertion) followed by any text 
   /$1XXX$3/              # the replacement string: first capturing group, followed by XXX instead of left home, followed by the rest of the text
   */
   replace1=prxchange(pattern1,-1,a);
   property=prxchange(pattern2,-1,a);

   pattern3=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home(10|\d))(.*)/$1YYY$3/');
   pattern4=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home(10|\d))(.*)/$2/');*# same as before only capturing the second group that is left home with specified digits;
   /*
   (.*(?&amp;lt;=Tasks:).*)      # Any text followed by Tasks: (as positive lookbehind assertion) followed by any text 
   (left home(10|\d))     # The text to search: left home, followed by 10 or any digit
   (.*)                   # Any text
   /$1YYY$3/              # the replacement string: first capturing group, followed by YYY instead of left home with specified digits, followed by any text in the 3rd capturing group
   */
   replace2=prxchange(pattern3,-1,a);
   variant=prxchange(pattern4,-1,a);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 09:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/557717#M155527</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-05-10T09:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/558119#M155731</link>
      <description>&lt;P&gt;Thank you dear Oligolas for your great response ! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; it's a good solution,&amp;nbsp;&lt;BR /&gt;may I precise how to capture the number after the home ?&amp;nbsp; example home&lt;STRONG&gt;8&lt;/STRONG&gt; , home&lt;STRONG&gt;9&amp;nbsp;etc&lt;/STRONG&gt; regardless of the space ( home8 or home &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;BR /&gt;what is the best way to do it ? with RE&amp;nbsp; ( \s?) or buil-in SAS functions ? what's your experience on thtis ?&lt;BR /&gt;Sincerely.&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2019 10:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/558119#M155731</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-12T10:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/558831#M155999</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you could define a new capturing Group for the numbers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length a $500;
a="some text here

reporting: by Mr. Jones

new 'left home' was selected

information:
the new home was found 
Tasks:
provide information about 'left home8'
";
run;

data want;
   length replace1 property replace2 variant $500;
   set have;

   pattern1=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$1XXX$3/');
   pattern2=prxparse('s/(.*(?&amp;lt;=reporting:).*)(left home)(.*(?=information:).*)/$2/');*# same as before only capturing the second group that is left home;
   /*
   (.*(?&amp;lt;=reporting:).*)  # Any text followed by reporting: (as positive lookbehind assertion) followed by any text
             (left home)  # The text to search: left home
   (.*(?=information:).*) # Any text followed by information: (as positive lookahead assertion) followed by any text 
   /$1XXX$3/              # the replacement string: first capturing group, followed by XXX instead of left home, followed by the rest of the text
   */
   replace1=prxchange(pattern1,-1,a);
   property=prxchange(pattern2,-1,a);

   pattern3=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home)(10|\d)(?!\d)(.*)/$1YYY$4/');
   pattern4=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home)(10|\d)(?!\d)(.*)/$2$3/');*# same as before only capturing the second group that is left home with specified digits;
   pattern5=prxparse('s/(.*(?&amp;lt;=Tasks:).*)(left home)(10|\d)(?!\d)(.*)/$3/');*# capture the specified digits;
   /*
   (.*(?&amp;lt;=Tasks:).*)        # Any text followed by Tasks: (as positive lookbehind assertion) followed by any text 
   (left home(10|\d))(?!\d) # The text to search: left home, followed by 10 or any (single) digit
   (.*)                     # Any text
   /$1YYY$3/                # the replacement string: first capturing group, followed by YYY instead of left home with specified digits, followed by any text in the 3rd capturing group
   */
   replace2=prxchange(pattern3,-1,a);
   variant=prxchange(pattern4,-1,a);
   number=prxchange(pattern5,-1,a);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 08:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/558831#M155999</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-05-15T08:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: find a phrase between two words using RE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/559567#M156270</link>
      <description>&lt;P&gt;Thank you for this, appreciate your great support !&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 06:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-phrase-between-two-words-using-RE/m-p/559567#M156270</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-17T06:50:27Z</dc:date>
    </item>
  </channel>
</rss>

