TextPad Regex: How to Find and Replace character within angle brackets?

2k Views Asked by At

I've got the below sample text

Hello | World
<Hi | Hello|How | are | you><test|string |for |regex>
sample | text <however|replace|pipe>

to be converted as below

Hello | World
<Hi ~ Hello~How ~ are ~ you><test~string ~for ~regex>
sample | text <however~replace~pipe>

i.e. Replace | within <> with ~

I tried this <(?:.*?)(\|)(?:.*?)> (http://regex101.com/r/mX1sO0)

But it matches only the first | withing the angle <>. And I am not sure how to replace it. Any directions?

1

There are 1 best solutions below

0
On BEST ANSWER

If your angle brackets are never nested and always correctly balanced, then you can do it:

\|(?=[^<>]*>)

matches only those pipe characters where the next angle bracket is a closing angle bracket. Then just replace the matches with ~.

See it live on regex101.com.