I'm going to try my best to explain this string manipulation.
I would like to write a JavaScript function that takes a string (preferably from a message textbox but it will be initially stored in a variable for this example) and looks for every instance of the power function "Pow()". Then, takes the contents of the "base" portion of the power function "Pow(base,exponent)" and replace it with the absolute function "Abs()" with the contents inside that so the result is "Pow(Abs(base),exponent)". The base can be anything; a word, an equation, or another function. result out to another message textbox.
for example
input:
return(1.0-step(snoise(vec2(5.0*pow(iGlobalTime,2.0)+pow(uv.x*7.0,1.2),pow((mod(iGlobalTime,100.0)+100.0)*uv.y*0.3+3.0,staticHeight))),staticAmount))*staticStrength;
output:
return(1.0-step(snoise(vec2(5.0*pow(abs(iGlobalTime),2.0)+pow(abs(uv.x*7.0),1.2),pow(abs((mod(iGlobalTime,100.0)+100.0)*uv.y*0.3+3.0),staticHeight))),staticAmount))*staticStrength;
I'm well aware of the .match and string.replace() functions but this is a little more complex. Can anyone lead me in the right direction?
<textarea id = "output" rows="25" cols="55" ></textarea>
<script>
inputStr = "return(1.0-step(snoise(vec2(5.0*pow
(iGlobalTime,2.0)+pow(uv.x*7.0,1.2),pow
((mod(iGlobalTime,100.0)+100.0)*uv.y*0.3+3.0,
staticHeight))),staticAmount))*staticStrength;"
function baseReplacer(input)
{
}
var outputStr = baseReplacer(inputStr);
document.getElementById("output").value = outputStr;
</script>