Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP find in between nuances

Return to Member Forum

  • Author
    Posts
    • #14335717
      Austin
      Participant

      Hello,

      I had a question about using GREP to find in-between 2 characters — in this case everything between 2 #’s. I have a GREP forumula that does so, (?<=#).+?(?=#), and below is an example of what I want changed. The first change i would want would be between (1) and (2). The next change would be between (3) and (4), and so on. Unfortunatley what is happening is that it is basically changing everything between (1) and (6) as it is looking at them with overlapping pairs — (1) and (2), (2) and (3), (3) and (4), etc — as they all appear in the same paragraph. Example:

      Alec Zajac is a winter editorial intern for (1)#DBusiness#(2). During his time with the publication, he contributed articles to the On the Move and Give Detroit Spotlight sections of the (3)#DBusiness#(4) website, and to the (5)#DBusiness Daily News#(6)

      My question is is there any way to get it to change the way I want without having to check each change? My hunch is no, but I am hoping to be proven wrong.

      Thank you!
      Austin

    • #14335718

      Do you need the found text to include the # characters?
      And what happens next – change to what? i.e. what would the sample paragraph look like after the find/change?

      • #14335721
        Austin
        Participant

        I am changing all the words in between to italics. I work for a media group that publishes magazine and the #’s are the editors way of denoting what needs to be italicized. I’m trying to automate the process of doing it just for efficiency’s sake.

        The # character could be included, and in fact, if it were included that might solve the problem as I could change my search parameters to include a find style for a non-italicized font, and then once its converted it would no longer show up in the search results.

        So I guess my question now becomes how do I include the # characters in the italicization while still searching between those two characters?

    • #14335719

      Hi

      In stead of using .+? which is greedy
      try using .*?

    • #14335722
      Austin
      Participant

      I tried it, but it still resulted in the same issue. My understanding of the difference between * and + is just that * searches for 0 or more of the preceding command, and + searches for 1 or more, which when breaking it down that way would show that it wouldn’t make a difference in this situation.

      I use the * command, as an example, when searching for a string of words that might have a comma or space between them, but also might not.

    • #14335724
      Dennis Griffin
      Participant

      I tried this and it seemed to work.

      (?<=#)[\w ?]+?(?=#)

      I’m pretty new at this so I’m not sure if this is what you’re looking for.

      • #14335730
        Austin
        Participant

        Thank you! This seems to work, aside from one spot and its really confusing me. The code is changing each one as it I wanted, except when it comes to between (6) and (7). The “and” is being changed and I can’t figure out why. I tried adding extra words to see if it was an issue of it just being one word in between, but that wasn’t the case. Any thoughts on this? I’m very very new at this all myself. Paragraph from indesign below:

        ALEC ZAJAC is a winter editorial intern for (1)#DBusiness#(2). During his time with the publication, he contributed articles to the On the Move and Give Detroit Spotlight sections of the (3)#DBusiness#(4) website, and to the (5)#DBusiness Daily News#(6) and (7)#DBusiness Tech and Mobility News#(8) newsletters.

    • #14335729
      David Blatner
      Keymaster

      Great suggestions here! It’s always awesome when the community makes suggestions like this, and there’s usually more than one way to do something, especially when it come to GREP.

      Here’s another way:
      Search for (#)([\w]+?)(#)
      and replace with $2
      That finds the number sign, followed by anything that is a word character or a space character, followed by a number sign, and then it replaces it with whatever #2 — that is, the words between the # symbols. You can then set the Find Format field to your italic style.

      • #14335732
        Austin
        Participant

        Thank you, David!

        Ive read a bunch of your articles and such on GREP to help me get a basic understanding of it in regards to InDesign. I’m still pretty new at it. This code is perfect and kills two birds with one stone. I was about to setup a script with ChainGREP that changed everything to italics and then deleted the #’s with two separate queries, but no need now!

        I appreciate your help and everyone else’s responses as well. Thank you everyone.

    • #14335731
      Dennis Griffin
      Participant

      I just tried copying and pasting that expression and using it on the sample paragraph provided and it wouldn’t find anything. Am I doing something wrong?

    • #14335733
      Austin
      Participant

      David’s expression?

      I had that trouble at first as well, but noticed the left bracket was left out.
      Find: (#)([\w]+?)(#)
      Change: $2

      Change format: italics

      Try that

      • #14335763
        David Blatner
        Keymaster

        Thank you, Austin! Sorry about that. I have now fixed my code above.

    • #14335783
      Dennis Griffin
      Participant

      Thank you Austin and David. I understand now how David’s solution is the better option. I wasn’t addressing the entire problem. I wasn trying to delete the # signs as required. Fun though. Trying to get GREP expressions to work is great for exercising your brain cells sometimes. Better than Word Jumbles! Big fan, David.

Viewing 8 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads