[erlang-questions] backquotes in re:replace/3

Erik Søe Sørensen eriksoe@REDACTED
Thu Mar 8 19:41:02 CET 2012


That's not a digit; that's an ASCII 1.
For the digit "1", you'd need
4> re:replace("012345", "0(...)45", "x\\1\61").
which of course doesn't work either.

"man pcresyntax" really does indicate that "\g{N}" would be the expected 
PCRE syntax for the job:

    BACKREFERENCES
              \n             reference by number (can be ambiguous)
              \gn            reference by number
              \g{n}          reference by number
              \g{-n}         relative reference by number

but "\\g" does not appear to be supported in any form...

And the workaround I can think of - using an empty quoted section as a 
separator - doesn't work either:
2> re:replace("012345", "0(...)45", "\\1\\Q\\E6789").
[[<<"123">>,<<"QE6789">>]]

/Erik

Den 08-03-2012 19:01, Gustav Simonsson skrev:
> Is this what you want todo?
>
> re:replace("012345", "0(...)45", "x\\1\1").
> [[<<"x">>,<<"123">>,<<1>>]]
>
> Regards,
> Gustav Simonsson
>
> Sent from my PC
>
> ----- Original Message -----
>> From: "Vance Shipley"<vances@REDACTED>
>> To: erlang-questions@REDACTED
>> Sent: Thursday, 8 March, 2012 4:58:19 PM
>> Subject: [erlang-questions] backquotes in re:replace/3
>>
>> Is there a syntax supported which allows us to insert a back
>> reference in a replacement followed directly by digits?  I
>> haven't found one yet.
>>
>>     Eshell V5.9  (abort with ^G)
>>     1>  re:replace("012345", "0(...)45", "\\1bcde").
>>     [[<<"123">>,<<"bcde">>]]
>>     2>  re:replace("012345", "0(...)45", "\\16789").
>>     [[<<>>]]
>>     3>  re:replace("012345", "0(...)45", "\\g{1}6789").
>>     [<<"g{1}6789">>]
>>
>>
>> --
>> 	-Vance
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

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


More information about the erlang-questions mailing list