I am using node.js and express.
I have a string similar to the following:
Here is my string but now I need to processString("mystring")
and return the processString("data").
I want to search for all occurrences of processString and replace it with the results of a function. The function I need to run is asynchronous. Is there an easy way to do this?
Thanks!
Your question isn't really to clear, the "why" and "what" may be more helpfull in answering your question. From what I understand you want to replace processString("****")
with ****
in which case you can use the following:
var str = 'Here is my string but now I need to processString("mystring") and return the processString("data").'
str = str.replace(/processString\(\".*?\"\)/gi, function(match){
return match.replace("processString\(\"", "").replace("\"\)", "")
})
console.log(str);
This will match the processString("****")
inner contents, hope this is what you were looking for!