<?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 Problem with call prxnext if the first match is zero-length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-call-prxnext-if-the-first-match-is-zero-length/m-p/817997#M322872</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having issues parsing strings with leading blanks with call prxnext if the first match is zero-length. This is the string to parse:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; foo        foo foo foo foo&lt;/PRE&gt;&lt;P&gt;and here is the code snippet:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data read;
	length var $50;
	input var char50.;
	datalines;
 foo        foo foo foo foo
 ;
run;

data regex;
	set read;
	regex = prxparse("/(?:^| )([a-z\-]*)(?= |$)/");
	start = 1;
	stop = length(var);
	call prxnext(regex, start, stop, trim(var), pos, len);

	do while (pos GT 0);
		var_tall = prxposn(regex, 1, trim(var));
		output;
		call prxnext(regex, start, stop, trim(var), pos, len);
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that:&lt;/P&gt;&lt;P&gt;- only twelve matches are found while there are thirteen present&lt;/P&gt;&lt;P&gt;- the first zero-length match seems to overwrite the first non-zero one&lt;/P&gt;&lt;P&gt;regex101.com finds 13 matches as expected. Is this a bug in SAS? Or in my code? Thank you for your help in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jun 2022 06:28:21 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2022-06-14T06:28:21Z</dc:date>
    <item>
      <title>Problem with call prxnext if the first match is zero-length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-call-prxnext-if-the-first-match-is-zero-length/m-p/817997#M322872</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having issues parsing strings with leading blanks with call prxnext if the first match is zero-length. This is the string to parse:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; foo        foo foo foo foo&lt;/PRE&gt;&lt;P&gt;and here is the code snippet:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data read;
	length var $50;
	input var char50.;
	datalines;
 foo        foo foo foo foo
 ;
run;

data regex;
	set read;
	regex = prxparse("/(?:^| )([a-z\-]*)(?= |$)/");
	start = 1;
	stop = length(var);
	call prxnext(regex, start, stop, trim(var), pos, len);

	do while (pos GT 0);
		var_tall = prxposn(regex, 1, trim(var));
		output;
		call prxnext(regex, start, stop, trim(var), pos, len);
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that:&lt;/P&gt;&lt;P&gt;- only twelve matches are found while there are thirteen present&lt;/P&gt;&lt;P&gt;- the first zero-length match seems to overwrite the first non-zero one&lt;/P&gt;&lt;P&gt;regex101.com finds 13 matches as expected. Is this a bug in SAS? Or in my code? Thank you for your help in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 06:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-call-prxnext-if-the-first-match-is-zero-length/m-p/817997#M322872</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-06-14T06:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with call prxnext if the first match is zero-length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-call-prxnext-if-the-first-match-is-zero-length/m-p/817999#M322873</link>
      <description>&lt;P&gt;This works for some reason:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data read;
	length var $50;
	input var char50.;
	datalines;
 foo        foo foo foo foo
 ;
run;

data regex;
	set read;
	regex = prxparse("/(?:(?&amp;lt;=^)|(?&amp;lt;= ))([a-z\-]*)(?= |$)/");
	start = 1;
	stop = length(var);
	call prxnext(regex, start, stop, trim(var), pos, len);

	do while (pos GT 0);
		var_tall = prxposn(regex, 1, trim(var));
		output;
		call prxnext(regex, start, stop, trim(var), pos, len);
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 06:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-call-prxnext-if-the-first-match-is-zero-length/m-p/817999#M322873</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-06-14T06:41:04Z</dc:date>
    </item>
  </channel>
</rss>

