Find this, then not-that, then-this

General questions about using TextPad

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

Post Reply
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

Find this, then not-that, then-this

Post by redcairo »

I've been able to figure out lots of my own stuff thanks to the education in this forum, thanks for that.

There's one thing I haven't done yet and I'm stuck on it.

I have some lines (options in multiple choice questions, they always begin with a letter, period, space) which due to a software error, are stripping out the necessary string "Incorrect. " from the front of incorrect options. The correct option(s) is fine. So I'm trying to write a regex that basically says something like:

^([a-f]. ){insert logic like' ONLY if the next text is NOT "Correct." ' here}(.*[^ ] *)$

What I have now:

a. Something here
b. Correct. (This correct value could be in any one or more of the letter options, it varies.)
c. Something else
d. And yet another
e. And yet another
f. And yet another

What I'd like to end up with:


a. Incorrect. Something here
b. Correct. (This correct value could be in any one or more of the letter options, it varies.)
c. Incorrect. Something else
d. Incorrect. And yet another
e. Incorrect. And yet another
f. Incorrect. And yet another


I hope I've asked this properly. I've seen that communicating clearly what I need, I'm sometimes worse at than writing regex! I greatly appreciate any help.

Best,
PJ

PS I did figure out how to do it in TWO steps:

step 1: (posix/regex)

search: ^([a-f]. )(.*[^ ] *)$

replace: \1Incorrect. \2

step 2: (posix/regex) to clean it up

search: ^([a-f]. )Incorrect. Correct. (.*[^ ] *)$

replace: \1Correct. \2

I was just hoping for something more elegant + I thought I'd learn something I didn't know.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Using TextPad's weak regular expression recogniser it's not possible to search for text not containing some arbitrary string. Two steps, such as the ones you suggest, are necessary. You can, however, do this using WildEdit (http://www.textpad.com/products/wildedit/), using negative look-ahead.
Post Reply