gulp-string-replace icon indicating copy to clipboard operation
gulp-string-replace copied to clipboard

stuff in brackets seems not to make it to the replacement

Open jobe451 opened this issue 7 years ago • 2 comments

I don't get the replacement with $1 running.

I copied this rule from the examples to my code (after trying for some time more sensible stuff):

pipe(replace(/version(={1})/g,` '$1v0.2.2')

In my HTML-File I have this

...
version=1
...

I would expect to see this output on the command line (since the bracktes match the single = character)

Replaced: "version=" to "=v0.2.21" in a file:

However, what I get is that:

Replaced: "version=" to "$1v0.2.21" in a file:

I would expect it to work the same, as I type this on the browser console (which also returns "=v0.2.21"),

"version=1".replace(/version(={1})/g, '$1v0.2.2');

What did I not understand?

jobe451 avatar Nov 01 '18 14:11 jobe451

Hi, sorry for the delay, I'll check this issue tomorrow at the latest.

tomaszczechowski avatar Nov 12 '18 06:11 tomaszczechowski

Hi,

Firstly, apologies for the delay in answering. Secondly, I checked your case and indeed there is an issue. Unfortunately, the possible solution won't be easy and likely I'd have to release 2.0 version with a bit different API.

For a time being please use this workaround:

.pipe(replace(/version(={1})/g, function() {
      return '=v0.2.2';
}));

you would see this in a console: Replaced: "version=" to "=v0.2.2" in a file:

nevertheless an outcome would be good:

=v0.2.21

please try yourself and let me know if there is anything else you're struggling with.

In meantime I would preapre new version of it.

tomaszczechowski avatar Dec 18 '18 20:12 tomaszczechowski