<?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: Regular Expression pattern matching in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631790#M187216</link>
    <description>&lt;P&gt;The O modifier is unnecessary in this case anyway. It only matters when the RX string contains variables, if the string is a constant, the expression is compiled only once.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Mar 2020 07:02:31 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-03-13T07:02:31Z</dc:date>
    <item>
      <title>Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631742#M187199</link>
      <description>&lt;P&gt;Hello Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was trying to extract string between parenthesis and using regular expression. I was able to extract the first occurrence,&amp;nbsp;&amp;nbsp;but want all the values if multiple parenthesis exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
length char_var $100.;
input char_var $1-100;

if _n_=1 then do;
 retain re;

 re = prxparse('/\(([^()]*)\)/'); /* How to define my pattern here?*/

if missing(re) then do;
 putlog 'ERROR: regex is malformed';
 stop;
 end;
 end;

if prxmatch(re,char_var) then do;&lt;BR /&gt;char_var_new = prxchange('s/\(([^\)]+)\)//i',-1,char_var); /* I want all the values that were removed here */
code1 = prxposn( re, 1, char_var);
code2 = prxposn( re, 2, char_var);
/* call prxposn( re, 1, endgstart, endglen);*/
/* code = substr(char_var,endgstart,endglen);*/
output;
end;

datalines;
1111, 2222 (0000)
1111 (11, 22, 33, 44)
90658
11(00),33(111)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Mar 2020 23:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631742#M187199</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2020-03-12T23:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631748#M187200</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;re = prxparse('/ \( ( [^()]+ ) \) .*? ( \( ( [^()]+ ) \) )? /x'); 

code1 = prxposn( re, 1, char_var);
code2 = prxposn( re, 3, char_var);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;re = prxparse('/ \( ( [^()]+ ) \) .*? (?: \( ( [^()]+ ) \) )? /x'); 

code1 = prxposn( re, 1, char_var);
code2 = prxposn( re, 2, char_var);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 00:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631748#M187200</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-13T00:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631749#M187201</link>
      <description>&lt;P&gt;Below code should give you the idea.&lt;/P&gt;
&lt;P&gt;The RegEx uses a positive look behind and look ahead (highligted).&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 144px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36825iF11B76725E11ED02/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need an _n_=1 clause for the prxparse() bit. SAS will compile the RegEx only once also if using syntax as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  length char_var $100.;
  input char_var $1-100;
  datalines;
1111, 2222 (0000)
1111 (11, 22, 33, 44)
90658
11(00),33(111)
;

data want;
  _inrowId=_n_;
  set have;
  _prxid = prxparse('/(?&amp;lt;=\().+?(?=\))/oi');
  _start = 1;
  _stop = length(char_var);

  /* Use PRXNEXT to find the first instance of the pattern, */
  /* then use DO WHILE to find all further instances.       */
  /* PRXNEXT changes the _start parameter so that searching  */
  /* begins again after the last match.                     */
  call prxnext(_prxid, _start, _stop, char_var, _pos, _len);
  if _pos&amp;lt;=0 then output;
  else do while (_pos &amp;gt; 0);
    found = substr(char_var, _pos, _len);
    put found= _pos= _len=;
    output;
    call prxnext(_prxid, _start, _stop, char_var, _pos, _len);
  end;
run;

proc print data=want;
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>Fri, 13 Mar 2020 00:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631749#M187201</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-13T00:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631756#M187203</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; Neatest by virtue of solution,comments and approach. Most will/should understand the exquisite &lt;U&gt;&lt;STRONG&gt;algo-rhythm&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp;of yours. Priceless. &lt;STRONG&gt;Thank you 1E6&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS I really do like the O modifer forcing to compile only once&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 01:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631756#M187203</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-13T01:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631790#M187216</link>
      <description>&lt;P&gt;The O modifier is unnecessary in this case anyway. It only matters when the RX string contains variables, if the string is a constant, the expression is compiled only once.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 07:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631790#M187216</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-03-13T07:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631803#M187219</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The O modifier is unnecessary in this case anyway. It only matters when the RX string contains variables, if the string is a constant, the expression is compiled only once.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Very true. I just made it a coding habit for myself to always use it unless there is a reason not to.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 09:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631803#M187219</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-13T09:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression pattern matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631851#M187242</link>
      <description>&lt;P&gt;Thank you! This is very helpful and informative.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 13:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-Expression-pattern-matching/m-p/631851#M187242</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2020-03-13T13:30:29Z</dc:date>
    </item>
  </channel>
</rss>

