Regex: Match all text in a string besides encapsulated text

captchaman

Junior Member
Joined
Sep 16, 2010
Messages
192
Reaction score
848
I'm shit with regex but what I'm trying to achieve is simple: I want to replace a word if found with another word, unless the text is encapsulated, then ignore it.

I want to turn this:
Code:
This is an example. {Examples are} great.
into this:
Code:
This is an replacement text. {Examples are} great.

How would I achieve this?

Thanks,
CM
 
One thing you can try is to replace everything in { } with Id(or something that you know that will not repeat. Then you replace all the text you want. And then you can put all the text back.

This is an example. {Examples are} great.

to

This is an example. Id_1 great.
(Note that you will have to store Id_1 map to {Examples are})
to
This is an replacement text. Id_1 great.
to
This is an replacement text. {Examples are} great.
 
I already hacked it together so it works, I just wanted to be able to do it the proper way. Thanks anyway.
 
Back
Top