[erlang-questions] Backreferences with re module

Technion technion@REDACTED
Sun Apr 22 13:53:24 CEST 2018


Hi,


I seem to be having some issues with the re: module any time a back reference is introduced.


(yes, I ideally wouldn't use a regex, I have one place I really need to)


Referencing the module manual here:

http://erlang.org/doc/man/re.html


A specific example is given:


Consider, for example:
(.*)abc\1
If the subject is "xyz123abc123", the match point is the fourth character.


However, I've simplified my code down to that exact example and I can't make it match:


46> {ok, MP} = re:compile("(.*)abc\1").
{ok,{re_pattern,1,0,0,
                <<69,82,67,80,89,0,0,0,0,0,0,0,65,1,0,0,255,255,255,255,
                  255,255,...>>}}
47> re:run("xyz123abc123", MP, [{capture,all_names,binary}]).
nomatch

I have written all manner of patterns without a back reference that return a match fine:


48> {ok, MP2} = re:compile("(.*)abc123").
{ok,{re_pattern,1,0,0,
                <<69,82,67,80,93,0,0,0,0,0,0,0,65,1,0,0,255,255,255,255,
                  255,255,...>>}}
50> re:run("xyz123abc123", MP2, [{capture,all,binary}]).
{match,[<<"xyz123abc123">>,<<"xyz123">>]}

My platform:

Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)

The presented syntax works perfectly fine in Ruby, further suggesting the regex is correct:

irb(main):001:0> /(.*)abc\1/.match("xyz123abc123")
=> #<MatchData "123abc123" 1:"123">


Any assistance on this is appreciated.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180422/a424bbbc/attachment.htm>


More information about the erlang-questions mailing list