[erlang-questions] Backreferences with re module

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


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:


A specific example is given:

Consider, for example:
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").
47> re:run("xyz123abc123", MP, [{capture,all_names,binary}]).

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

48> {ok, MP2} = re:compile("(.*)abc123").
50> re:run("xyz123abc123", MP2, [{capture,all,binary}]).

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