<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 22, 2018 at 7:53 AM, Technion <span dir="ltr"><<a href="mailto:technion@lolware.net" target="_blank">technion@lolware.net</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">
<div dir="ltr">
<div id="gmail-m_-4368026255162066515divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0px;margin-bottom:0px">Hi,</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">I seem to be having some issues with the re: module any time a back reference is introduced.</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">(yes, I ideally wouldn't use a regex, I have one place I really need to)</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">Referencing the module manual here:</p>
<p style="margin-top:0px;margin-bottom:0px"><a href="http://erlang.org/doc/man/re.html" class="gmail-m_-4368026255162066515OWAAutoLink" id="gmail-m_-4368026255162066515LPlnk416354" target="_blank">http://erlang.org/doc/man/re.<wbr>html</a></p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">A specific example is given:</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px"></p>
<div><i>Consider, for example:</i><br>
<i>(.*)abc\1<br>
If the subject is "xyz123abc123", the match point is the fourth character. </i></div>
<br>
<p></p>
<p style="margin-top:0px;margin-bottom:0px">However, I've simplified my code down to that exact example and I can't make it match:</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>46> {ok, MP} = re:compile("(.*)abc\1").</div></div></div></blockquote><div><br></div><div>You need a double backslash here instead:</div><div><br></div><div>{ok, MP} = re:compile("(.*)abc\\1"). </div><div><br></div><div>Look at the note near the top of the re man page <a href="http://erlang.org/doc/man/re.html">http://erlang.org/doc/man/re.html</a> :</div><div><br></div><div>'The Erlang literal syntax for strings uses the "\" (backslash) character as an escape code. You need to escape backslashes in literal strings, both in your code and in the shell, with an extra backslash, that is, "\\".'</div><div><br></div><div>--steve</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div id="gmail-m_-4368026255162066515divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<div>{ok,{re_pattern,1,0,0,</div>
<div> <<69,82,67,80,89,0,0,0,0,0,0,<wbr>0,65,1,0,0,255,255,255,255,</div>
<div> 255,255,...>>}}</div>
<div>47> re:run("xyz123abc123", MP, [{capture,all_names,binary}]).</div>
<div>nomatch</div>
<div><br>
</div>
I have written all manner of patterns without a back reference that return a match fine:
<p></p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>48> {ok, MP2} = re:compile("(.*)abc123").</div>
<div>{ok,{re_pattern,1,0,0,</div>
<div> <<69,82,67,80,93,0,0,0,0,0,0,<wbr>0,65,1,0,0,255,255,255,255,</div>
<div> 255,255,...>>}}</div>
<div><span style="font-size:12pt">50> re:run("xyz123abc123", MP2, [{capture,all,binary}]).</span><br>
</div>
<div>{match,[<<"xyz123abc123">>,<<"<wbr>xyz123">>]}</div>
<div><br>
</div>
<div>My platform:</div>
<div><br>
</div>
<div>
<div>Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]</div>
<div><br>
</div>
<div>Eshell V9.3 (abort with ^G)</div>
<div><br>
</div>
<div>The presented syntax works perfectly fine in Ruby, further suggesting the regex is correct:</div>
<div><br>
</div>
<div>
<div>irb(main):001:0> /(.*)abc\1/.match("<wbr>xyz123abc123")</div>
<div>=> #<MatchData "123abc123" 1:"123"></div>
<div><br>
</div>
<br>
</div>
Any assistance on this is appreciated.</div>
<br>
<p></p>
<br>
</div>
</div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>