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

Finding partial words in italics

Return to Member Forum

  • Author
    Posts
    • #14358795
      Brad Grigor
      Member

      In my text, I have cases where italics have been applied to only part of a word. I need to find these cases and either remove the italics style or apply it to the whole word. The challenge is to find just the cases of italics that aren’t whole words. But I can’t seem to formulate a Find/Change expression to do this. The problem is the Find character style option applies to the entire search expression. Is there another way to automate this search?

      Many thanks for your help!

    • #14358801
      Petar Petrenko
      Participant

      Sorry if I posted more times the same reply, but when I hit the “Submit” button I can’t see my answer.

      • #14358804
        David Blatner
        Keymaster

        Sorry, Petar. I’m not sure why that was stuck in moderation. I have approved it now.

    • #14358800
      Petar Petrenko
      Participant

      Hi Brad,
      my opinion is that you can solve this only by using GREP. You can foind on Facebook a froup named “The Treasures of GREP” where you can ask the members to help you solve the problem.

      • #14358805
        Brad Grigor
        Member

        Thanks Petar. There are times like this when having a Facebook account would be useful. :-)

        But even with GREP, is it actually possible to formulate a search where a style applies to only part of the search result, e.g. match <beginning of word><one or more non-italic letters><one or more italic letters><end of word>?

    • #14358806
      Petar Petrenko
      Participant

      Thank you, David.

    • #14358808
      David Blatner
      Keymaster

      Unfortunately, GREP only knows characters, not formatting. So I don’t think this is possible. (Happy to be proven wrong if someone else has an answer!)

      You might be able to figure this out by exporting the story as Tagged Text, and then using GREP on that plain text. It’s VERY geeky but it can work. I wrote about something like this here:

      GREP Find/Change on Formatted Text (solution to a big problem)

    • #14358809
      Dhafir Photo
      Participant

      By 3 steps in GREP tab of Find/Change window:

      1. Add non joiner to the end of the italic:
      in Find: [\S]+
      in Find Format: italic
      in Change: $0~j

      2. Find non italic
      in Find: ~j\p{l*}+
      in Change Format: Italic

      3. Delete non joiner character
      if Find: ~j
      in Change: Leave empty

      • #14358815
        Brad Grigor
        Member

        I agree with David–brilliant! Very mathematical thinking–change the unsearchable into something searchable, and then change it back. I’m going to try it. Thanks so much.

    • #14358812
      David Blatner
      Keymaster

      Dhafir, that’s brilliant. Love it! Thank you. However, I think this will only work if the first part of a word is italic and the last part is not italic.
      If the first two letters of the word are not italic, and the rest are italic, you would have to do the opposite, yes?

      • #14358821
        Brad Grigor
        Member

        “Do the opposite. . .”, yes indeed. I’m giving a try right now.

      • #14358839
        Dhafir Photo
        Participant

        Actually you can use global change for convert all words to italic:

        1.
        in Find: [\S]+
        in Find Format: italic
        in Change: $0~j

        2.
        in Find: \p{l*}*~j\p{l*}*
        in Change Format: italic

      • #14362670
        Tobias Wantzen
        Participant

        Thanks Dhafir for this excellent GREP you shared!

        But I’d not do this with a global “change to”. At least in my language (German) it is possible to emphasize part of a word by italicising it, which looks e.g. like this: “<i>weg</i>schauen”.

        For me this will be a “manual GREP walk” through my text.

        Thanks, Tobias

    • #14358859
      David Blatner
      Keymaster

      What?! Dhafir… that is magic. Can you help us understand why this works?
      [\S]+ means “find one or more characters that that are either a horizontal space OR not a space”? That doesn’t make sense to me.
      And \p{l*}*~j\p{l*}* is really a mystery to me. I know ~j is the non-joiner, but… huh?!

      • #14358863
        Dhafir Photo
        Participant

        Hello David!
        Let’s to dive
        \S means any character except whitespace or break character, means horizontal white space and tab
        so [\S]+ with find format italic, will match everything in italic except breaks.
        Then put “non-joiner” (or any other zero width character such as “End Nested Style Here”) after the last italic character found.
        Now, you’ll find the letters before and after non-joiner, and make it italic, by: \p{l*}*~j\p{l*}*
        \p{l*} Any letter of any language
        * Does not exist or exists many times
        The trick is using the non-joiner as location pointing to the presence a letter \p{l*} in italic before or after it.

      • #14358955
        David Blatner
        Keymaster

        Intersting… but I still do not see why you include
        You do not want to include horizontal spaces that are italic, do you? It seems like \S+ would be enough. No?

      • #14359100
        Dhafir Photo
        Participant

        The main reason to include the horizontal space
        because if there one or more lines are italic, we need to specify the end of it only, not every word in it

      • #14359101
        Dhafir Photo
        Participant

        More explanations
        \S+ Matching anything in italic except the space, so it will matching every word in the italic line
        [\S]+ Matching the end of the italic line, because we don’t need matching every italic word, but we need “Finding partial words in italics” as in the title!

    • #14358865
      Godfried Vonk
      Participant

      Dhafir, just curious, why do you use [\S]+ in stead of .+?

      • #14358868
        Dhafir Photo
        Participant

        There is no difference between the code dot .+ and this regex, but I usually use this because it’s faster than the dot in search. (For me)
        By the way, in this particular case, you can use many other codes or regex to catch the same result:
        .+
        \C+
        \p{any}+
        \p{assigned}+
        [\V\v]+
        [\W\w]+
        [\H]+
        [\D\d]+
        [\S]+
        or [\S]+

    • #14362671
      David Blatner
      Keymaster

      Quick update: Mike Rankin explains this tip with images here:

      How to Find and Fix Partially Italic Words with GREP

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