replace string that does NOT contain another string

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
jur

replace string that does NOT contain another string

Post by jur »

Is there a way to find (and replace) a string that does NOT contain another specified string?

For example, I would like to find
{a string <i>enclosed</i> in curly brackets}
like that, that does not also contain a </chp> tag, but does contain other tags, as in the next example
{another </chp>string <i>enclosed</i> in curly brackets}
nnposter

Re: replace string that does NOT contain another string

Post by nnposter »

Let's say that the text does not contain tildas ( ~ ) and backticks ( ` ) at all and that curlies are not nested. This should then work:

1. Replace curlies with tildas and backticks when </chp> is inside the curlies:
\{([^}]*</chp>[^}]*)\} ---> ~\1`

2. Do your normal replacement:
(\{[^}]*)enclosed([^}]*\}) ---> \1replacement\2

3. Convert tildas and backticks back to curlies:
~([^~`]*)` ---> {\1}


Even better, you could tokenize the </chp> tag:

1. Replace all </chp> with tildas

2. Do your normal replacement (unless it contains a tilda):
(\{[^~}]*)enclosed([^~}]*\}) ---> \1replacement\2

3. Replace tildas with </chp>
Post Reply