I am sure that there is a trivial solution to this question, but I can’t understand that this is correct:
I want to replace a specific pattern in a string only if the entire string matches the regular expression.
So, in my case, the three pipes |should be replaced with underscores _only if the whole line is numbers and pipes:
|||10|||-80|||-120|||400 ---> replace
|||10|||asdf|||-120|||400 ---> don't replace
|||10|||-80|||400 ---> replace
|||10|||-80|||-120|||400|||test ---> don't replace
Expected Result:
___10___-80___-120___400
|||10|||asdf|||-120|||400
___10___-80___400
|||10|||-80|||-120|||400|||test
My attempts:
\|\|\|(?=\-?\d+)
replaces pipes if they are followed by numbers as expected, but, of course, also in "invalid" lines
^(\|\|\|\-?\d+){1,}$
matches the entire line and therefore I can not replace only pipes
, , , , , , .