Last active
November 3, 2016 13:18
-
-
Save dongyuwei/19b1e7491d7cebccc96b188fb93fc6b6 to your computer and use it in GitHub Desktop.
match && replace `require('foo')` in Erlang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
re:replace(<<"foo require('test.js') bar;\n require('test2.js');">>, "(require\\((.*)\\);?)", "<<\\g1>>--<<\\g2>>", [global, {return, list}]). | |
"foo <<require('test.js')>>--<<'test.js'>> bar;\n <<require('test2.js')>>--<<'test2.js'>>" | |
% "foo <<require('test.js')>>--<<'test.js'>> bar;\n <<require('test2.js')>>--<<'test2.js'>>" |
Author
dongyuwei
commented
Oct 30, 2016
\gN is back reference in Erlang
{ok, Js} = file:read_file("/Users/dongyuwei/code/erlang-elixir/CommonJS.erl/t.js").
re:replace(Js, "(require\\((['|\"])(.*?)\\g2\\);?)", "<<\\g1>>++<<\\g3>>", [global, {return, list}]).
cat t.js
require('foo.js');
var foo = 'bar';
require("bar.js") ;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment