<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Thanks a heap Steve. I must have read that man page a dozen times but that two liner escaped me every time.</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> vinoski@gmail.com <vinoski@gmail.com> on behalf of Steve Vinoski <vinoski@ieee.org><br>
<b>Sent:</b> Sunday, 22 April 2018 10:12:02 PM<br>
<b>To:</b> Technion<br>
<b>Cc:</b> erlang-questions@erlang.org<br>
<b>Subject:</b> Re: [erlang-questions] Backreferences with re module</font>
<div> </div>
</div>
<div>
<div dir="ltr"><br>
<div class="x_gmail_extra"><br>
<div class="x_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="x_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="x_gmail-m_-4368026255162066515divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif">
<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="x_gmail-m_-4368026255162066515OWAAutoLink" id="x_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="x_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="x_gmail-m_-4368026255162066515divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif">
<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>
</div>
</body>
</html>