i’m looking to change the following code:
x = 0;
dx = (val - (x * x)) / (2.0 * x);
x = x + dx;
diff = val - (x * x);
x = x;
return (x);
into:
VARIABLE_TO_MONITOR_x = 0;
dx = (val - (VARIABLE_TO_MONITOR_x * VARIABLE_TO_MONITOR_x)) / (2.0 * VARIABLE_TO_MONITOR_x);
VARIABLE_TO_MONITOR_x = VARIABLE_TO_MONITOR_x + dx;
diff = val - (VARIABLE_TO_MONITOR_x * VARIABLE_TO_MONITOR_x);
VARIABLE_TO_MONITOR_x = VARIABLE_TO_MONITOR_x;
return (VARIABLE_TO_MONITOR_x);
currently i’m using:
strLine.matches("^.*(?<![a-zA-Z])" +variableN[1] + "(?![a-zA-Z]).*$")
but this returns the following:
VARIABLE_TO_MONITOR_x = 0;
dVARIABLE_TO_MONITOR_x = (val - (VARIABLE_TO_MONITOR_x * VARIABLE_TO_MONITOR_x)) / (2.0 * VARIABLE_TO_MONITOR_x);
VARIABLE_TO_MONITOR_x = VARIABLE_TO_MONITOR_x + dVARIABLE_TO_MONITOR_x;
diff = val - (VARIABLE_TO_MONITOR_x * VARIABLE_TO_MONITOR_x);
VARIABLE_TO_MONITOR_x = VARIABLE_TO_MONITOR_x;
return (VARIABLE_TO_MONITOR_x);
how can i tweak this regex to to not catch instances that are not specifically the variable i am looking for? This catches instances where the variable is contained within another word…
any help would be greatly appreciated..
regex noob..
EDIT:
here is the code that replaces as well..
if (strLine.matches("^.*(?<![a-zA-Z])" + variableN[1] + "(?![a-zA-Z]).*$"))
{
strLine = strLine.replace(variableN[1], VARIABLES + variableN[1]);
}
This is a great time to use “word boundaries”!
will return an array of line pieces broken up by just your variable name exactly. “\b” matches the edge of a word.
You can then print it out a piece at a time using your new variable name to glue it together. Or better yet:
Will do all the replacement for you!