Reputation: 19049
I'm having following kind of content in my code:
something();_c.log(<ANY CONTENT HERE>);somethingElse();
Now I'd like to have a regexp that returns:
something();somethingElse();
For some reason I can't get this (easily) done. How can I achieve the desired result?
Upvotes: 0
Views: 59
Reputation: 11328
input = 'something();_c.log(<ANY CONTENT HERE>);somethingElse();'
input = input.replace(/_c.log\(.*?\);/g, "");
Upvotes: 0
Reputation: 39365
Can you use string replace with regex??
input = 'something();_c.log(<ANY CONTENT HERE>);somethingElse();'
input = input.replace(/(something\(\);).*?(somethingElse\(\);)/g, "$1$2");
Here it is capturing the two groups from your input and replacing everything excepts the two groups($1
, $2
).
If the something and somethingElse are unknown, and the _c.log is fixed over there, then use this one:
input = input.replace(/(\w+\(\);)_c\.log.*?(\w+\(\);)/g, "$1$2");
Upvotes: 2