Skip navigation
HG11
Currently Being Moderated

GREPS - excluding certain characters

May 31, 2013 2:11 AM

Hi all

 

Hope someone can advise? I need to apply a character style to reduce the size of punctuation characters within a paragraph - all fine, but I need to exclude the % symbol from this. Can anyone advise?

 

Thanks

 

H

 
Replies
  • Currently Being Moderated
    May 31, 2013 4:22 AM   in reply to HG11

    Try

     

    [[:punct:]](?<!%)

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2013 6:46 AM   in reply to HG11

    For the life of me, Eugene, I can't figure out why that works....

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2013 9:14 AM   in reply to Peter Spier

    [[:punct:]] is all punctuation

     

    (?<!) is a negative lookahead

     

    So it's looking for all punctuation - but take a peak ahead and don't include any %

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2013 9:50 AM   in reply to Eugene Tyson

    Actually, it's a neagtive lookbehind (the negative lookahead would be (?!) and it won't do what you want since most puntuation, including the % wouldn't be followed by another %). I think what's happening is that it finds the %, then looks behind (somehow that I don't understand) and sees the % and doesn't modify it. I was surprised that this syntax worked as I thought the lookbehinds needed to come before the search terms.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2013 1:30 AM   in reply to Peter Spier

    My apologies - I wrote the wrong explanation for the expression - it is a negative lookbehind.

     

    I never thought there were restrictions to the placements of the lookbehinds or lookaheads, positive or negative.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2013 3:34 AM   in reply to Eugene Tyson

    Perhaps no restrictions, but you definitely get what I would call some unexpected behaviors if you put lookbehinds after the search string or lookaheads before.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2013 4:50 AM   in reply to Peter Spier

    Peter Spier wrote:

     

    Perhaps no restrictions, but you definitely get what I would call some unexpected behaviors if you put lookbehinds after the search string or lookaheads before.

     

    You still get what you ask for. It's not very useful to preceed a constant text with a lookahead (since it would "always fail" or "always match"), but sometimes a construction like this can be handy:

     

    (?!999)\d\d\d

     
    |
    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