Skip to main content
Known Participant
December 3, 2021
Answered

GREP to find text between codes, italicize, remove codes

  • December 3, 2021
  • 2 replies
  • 619 views

I had a GREP search that was lost in an upgrade, and after an hour trying to reconstruct it, I've decided to approach the geniuses. I get plain text documents that come in with text that should italicized placed between bracketed codes thus:

 

<i>This Text Should Be Italic</i>

 

I want to italicize it and drop the codes thus:

 

This Text Should Be Italic

 

Simple enough for someone, unlike myself, who knows what she's doing. Much obliged to anyone who can help!

This topic has been closed for replies.
Correct answer brian_p_dts

Put a ? after the +. GREP is greedy by default. The ? limits that greediness. 

2 replies

Known Participant
December 3, 2021

as a result
(?<=<i>)(.+?)(?=</i>)

Known Participant
December 3, 2021

Thanks, Mehmet. The question mark did it.

 

Rob

Peter Spier
Community Expert
Community Expert
December 3, 2021

(<i>)(.+)(</i>)

change to $2 and add the italic formatting

Known Participant
December 3, 2021

Thanks so much! Almost there!

This works for the first find, Peter. But then, for some reason, the entire paragraph following is selected. As it happens that ¶ begins (after a quotation mark) with a coded phrase, and another shows up at the very end. See attached. Any ideas on why this would happen?

 

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
December 3, 2021

Put a ? after the +. GREP is greedy by default. The ? limits that greediness.