Skip navigation
Currently Being Moderated

GREP modifiers

Sep 24, 2010 8:53 AM

Ok - so how does one these things?

 

I've read the help - I've got a GREP manual from O'Reilly Media

 

But since CS3 I cannot understand how modifiers work.

 

Any of them, at all. Not sure when I should use them?

 
Replies
  • Currently Being Moderated
    Sep 24, 2010 9:26 AM   in reply to Eugene Tyson

    Is the GREP manual you have GREP in Indesign CS3/4 by Peter Kahrel? If so, look at pages 41-42 under "Single-line and Multi-line" for an explanation of multi-line and single line. Page 22 also has a bit of explanation about case-sensitive searches under "Replacing with Wildcards." The best example would be search where you want to find both Figure and figure. You would need to search for "(?i)figure".

     

    Page 52-53 also includes a brief key as to what each of the modifiers do. Good luck!

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2010 1:58 PM   in reply to Eugene Tyson

    Honestly, I've only used single-line or multi-line functionality once or twice. You would use it if you wanted to search for something that spans mutiple paragraphs, like any text that falls inbetween two numbers (see attached). This is necessary because the . wildcard finds everything except return characters. When I removed the single-line indicator (?s) and changed the GREP string to include standard carriage returns using either .+?|~b+? or [.~b]+? it couldn't return the same result. I think this is why the single-line and multi-line functionality exists.

     

    Case-sensitve modifiers can be used as outlined in my previous post, to find a string of characters no matter their case. Unlike text find/change, GREP find/change is case sensitive by default, so you have to use (?i) to turn it off.

     

    Matthew

    Screen shot 2010-09-24 at 4.45.00 PM.png

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2010 2:07 PM   in reply to Eugene Tyson

    From the documentation page on my own WhatTheGrep:

     

    (?i) (case insensitive)YES d
    (?s) (dot matches newlines)YES d
    (?m) (^ and $ match at line breaks)YES d (default mode)
    (?x) (free-spacing mode)YES d
    (?n) (explicit capture)no
    (?-ismxn) (turn off mode modifiers)YES d
    (?ismxn:group) (mode modifiers local to group)YES d
    d Any of i, s, m, x, or none at start, none or only one after the hyphen

     

    (The YES/no is whether ID supports the modifier.)

     

    Usage: something like (?i:this) to find case sensitive (the default) but "this" case insensitive. Or the other way around: (?i)Case sensitive but (?-i:this) not.

     

    (?m) is for "multiline mode", the default; (?-m) makes "^" and "$" functionally equal to \A and \Z (start and end of story). (?s) -- not the default -- makes . match a hard return, otherwise hard returns end a .+ sequence. (?-s).+ will match everything up to the end of story. (?x) turns on "comment mode": all regular spaces are ignored unless they are escaped with a \ (so the previous sentence will be searched as "turnson"comment mode":allregularspacesareignoredunlesstheyareescapedwitha " -- note the final space!), and in addition, everything after a '#' up to the end of the GREP expression (actually, the end of a single line) will also be ignored, so you can end all of your GREPs with (?x)# This is a comment.

     

    All of these should be explained in Peter's book! If you think it lacks detail, just say so, and he'll be sure to fix it in a next edition

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

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