GREP Replace Metacharacters

Learn / Forums / General InDesign Topics / GREP Replace Metacharacters

Viewing 2 reply threads
  • Author
    Posts
    • #81640
      Aaron Troia
      Participant

      I was doing a GREP search to capitalize the first letter at the beginning of multiple lines and I have no trouble finding the lower case but I cant seem to us \\u in replace to capitalize my search group for example:

      Find: ^\l
      Replace: \U$0\E

      This works in Sublime Text to capitalize, but cannot seem to figure out a way to do it in InDesign just with GREP, is there a way to do it? Are there metacharacters out there that will work in InDesign in a similar way? I understand Sublime and InDesign are using different GREP engines but it would be handy to use the uppercase/lowercase metacharacters in both find and replace, not just in find.

    • #81678
      Peter Kahrel
      Participant

      A. — This does doesn’t work in InDesign. Several feature requests have been submitted without much effect (please add your own).

      One workaround, if the font you use has All Caps, is to look for ^\l and apply allcaps.

      The other workaround is a script, which can be very simple in principle:

      app.findGrepPreferences = null;
      app.findGrepPreferences.findWhat = '^\\l';
      found = app.selection[0].findGrep();
      for (i = 0; i < found.length; i++) {
        found[i].contents = found[i].contents.toUpperCase();
      }

      This targets the current selection. To target the document, replace app.selection[0] with app.activeDocument in line 3.

      • #82092
        Aaron Troia
        Participant

        Peter,

        Thank you for your response, I dont know why I didn’t think to use ^\l with allcaps, it would’ve worked just as easily to do that as what I was trying to do (I apparently was not thinking outside the GREP box). Also thank you for that workaround script, that will come in handy next time.

        Aaron

    • #81684
      David Blatner
      Keymaster
      • #82093
        Aaron Troia
        Participant

        David,

        Thank you for those link, this is definitely something I need to read up on, I can’t believe I didn’t realized that InDesign didn’t do this until now.

        Aaron

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
>