I have plain text file (.txt) which has some expressions and I want to replace invalid expression with… …let’s say zero.
An invalid expression is expression which contains 1+3^4^5 or 10+3+4*5+2^5^6^7, i.e. an expression can’t contain number^number^number^..., it can only contain number^number.
I understand that best way to do this is to use Regex but I dont know how to write this in regex.
The regular expression that will detect multiple powers is
(
{2,}means two or more times in a row)Just ran the following Test:
Output was:
It failed to replace the trailing \d but it does work. You can grab the trailing \d with the following correction to the regex:
If you want to wipe out the entire expression that contains a double power just use
in your replace expresion. The
.*on either side will swallow up the entire string surrounding the double power when a replacement takes place.