Skip navigation
dave-o-design
Currently Being Moderated

GREP with multiple instances close to one another

Aug 6, 2012 8:14 PM

I'm having trouble with GREP outside of basics. I am using GREP to apply text styles to a paragraph. The text has been provided to me this way:

 

The colors starts as <ital>black<ital> and gradually progresses to <ital>white<ital>.

 

I'm using this: (<ital>).+(<ital>), which works fine in most circumstances. It fails on the above example, because it also italicizes "and gradually progresses to", which I don't want.

 

Can anyone be so kind as to point me in a direction of an explanation of what I'm doing wrong here?

 

Thanks in advance

 
Replies
  • Currently Being Moderated
    Aug 7, 2012 1:12 AM   in reply to dave-o-design

    I am unable to follow what you're doing. Can you post screen shots or simplify what you're doing?

     

    You mean the text comes to you with "<ital>black<ital>" in the text.

     

    So you want to make "black" italics? Or are you trying something else?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 1:31 AM   in reply to dave-o-design

    By default, GREP is Greedy and tries to match as much as text as possible. In your example

     

    dave-o-design wrote:

     

    The colors starts as <ital>black<ital> and gradually progresses to <ital>white<ital>.

     

    your match <ital>.+<ital> will match everything from the first to the last code. To switch to non-greedy mode, making it match the shortest possible match, change .+ to .+? like this:

     

    <ital>.+?<ital>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points