<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 18, 2013 at 12:41 PM, Paul Isambert <span dir="ltr"><<a href="mailto:zappathustra@free.fr" target="_blank">zappathustra@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">But then “abc” should be represented as “[ϵ][a][ϵ][b][ϵ][c][ϵ]” and<br>
“string.gsub("abc", ".*", "(%0)")” should return “()(abc)” or<br>
something like that? I’ll admit I can’t really get my head around it.<br>
</blockquote><div><br>abc=<br></div><div>target=[ϵ][a][ϵ][b][ϵ][c][ϵ]<br></div><div>pattern =ϵ | [^ϵ]+ (not sure about \n for Lua )<br></div><div>ϵaϵbϵc=abc =target[1]&target[2]&...&target[6] (low level loop greedy) => (ϵaϵbϵc) = (abc)<br>
ϵ=target[7] => (ϵ) =()<br><br></div><br><div>Why not the ϵ after c ?<br>From <a href="http://perldoc.perl.org/perlre.html" target="_blank">http://perldoc.perl.org/perlre.html</a><br><br>"By default, a quantified subpattern is "greedy", that is, it will match as
many times as possible (given a particular starting location) while still
allowing the rest of the pattern to match"<br><br>or as in <br>Repeated Patterns Matching a Zero-length Substring :<br></div><div><br>"The lower-level loops are <i>interrupted</i> (that is, the loop is
broken) when Perl detects that a repeated expression matched a
zero-length substring. "<br></div><div><br></div>Here the lower-level loops are those associated with the *+{} greedy quantifiers .<br><div>In this case ϵ after c is the zero-lenght substring and the the string is finished, so the first match is abc. <br>
</div><div><br>The global switch /g is the higher level loop:<br>"The higher-level loops preserve an additional state between iterations:
whether the last match was zero-length. To break the loop, the following
match after a zero-length match is prohibited to have a length of zero.
This prohibition interacts with backtracking (see <a href="http://perldoc.perl.org/perlre.html#Backtracking">Backtracking</a>),
and so the <i>second best</i> match is chosen if the <i>best</i> match is of
zero length."<br><br></div>which seems to be the case of the last ϵ.</div><div class="gmail_quote"><br><br></div><div class="gmail_quote">(at least for m; ne<span id="result_box" class="" lang="en"><span class="">edless to say the I reading the manual every time...)<br>
</span></span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
</div>Well, here things become strange. The regex in Vim script based on<br>
Perl, as far as I can tell. Now<br>
<br>
substitute('abc', '.*', '(\0)', 'g')<br>
<br>
returns the not-Perl-like “(abc)” instead of “(abc)()”, however<br>
<br>
substitute(';a;', 'a*', 'ITEM', 'g')<br>
<br>
returns the Perl-like “ITEM;ITEMITEM;ITEM” instead of the expected<br>
not-Perl-like “ITEM;ITEM;ITEM”.<br>
<br>
Well, I think I’ll write to the Vim list! :)<br>
<br></blockquote><div>I've tried with \zs\ze .. no luck.<br></div></div><br clear="all"><br>-- <br>luigi<br>
</div></div>