Find this, then not-that, then-this
Posted: Fri Aug 05, 2011 10:25 am
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.
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.