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

need grep help

Return to Member Forum

  • Author
    Posts
    • #82626
      Scott Rudy
      Participant

      i need help writing a simple grep…

      i need a grep that will bold between and including two enclosing characters…

      john doe, MD; jim q. public, MD*; Cindy E. Verybody, MD; Jill Neigh Bor,MD*

      i need it to bold jim q public, MD* and Jill Neigh Bor, MD* but not john and cindy (they do not have a *)

      what i have so far that does not work…
      (?<=;).*?(?=*)
      it does not know to stop at the first “;” it comes to and does not bold the “;” or the “*”

    • #82665
      Peter Kahrel
      Participant

      This is a tricky one. First of all, you need to escape the asterisk in your lookahead: use (?=\*), not (?=*) (because you’re after the * character literally, you don’t want to use it as an operator).

      But when you’ve fixed that you’ll find that the expression matches “jim q. public, MD” (as expected) and “Cindy E. Verybody, MD; Jill Neigh Bor,MD” (not expected). What you need to do is match from ; to * without any intervening ;. You can do that with this expression:

      (?<=;)[^;]+?(?=\*)

      Peter

    • #82698
      Scott Rudy
      Participant

      peter,
      unfortunately i am getting no response from that …
      i have tried to figure out the [^;] but am not savvy enough to grasp it…
      it means the character set of ; back to the beginning of the paragraph?

      because i cannot wrap my head around this i am unable to trouble shoot why i am getting nothing when i add this to my style sheet

      would you be so kind as to help a little more?

    • #82700
      Peter Kahrel
      Participant

      Strange, I copied the string from your original post and the Grep expression I suggested, and it works fine for me: the matches I get are “jim q. public, MD” and “Jill Neigh Bor,MD”. That’s correct, isn’t it? If it is, could you check the expression you used?

      As to [^;]+, ^ inside a character class means ‘not’. So [^;]+ means ‘mustn’t match a ; and the whole expression paraphrases as ‘match from ; up to * with no ; in between ; and *’.

    • #82712
      Scott Rudy
      Participant

      i tried it in a new document and it worked PERFECT!!!!
      i hope you have fun figuring out these grep that you help people with so freely. It is a great tool and i have done some really fun things with it but it frustrates me when i know i can see the pattern so i know it can be done, but cannot figure it out myself

      thanks for the assistance, thanks for the explanation and thank you your patience!!!!

      scott

    • #82729
      Paul White
      Member

      I could do with some help as well with Grep which is similar query!

      How do you do the first 2 words at the start of a paragraph. I think I am having a memory block today?

    • #82730
      Peter Kahrel
      Participant

      ^(.+?)(.+?)

      ^ from the start of a paragraph
      (.+?) capture characters
      up to the first space
      (.+?) capture characters after the space
      up to the second space

      Refer to the first word (in the Change to field) using $1, the second word, $2

      Peter

    • #82810
      Paul White
      Member

      Hi Peter thanks for your reply. It doesn’t work on my document

      John Bishop has been married to his wife Melanie since 1993, with an 18 month separation that began in 2000.[22][23] They have three sons: Joe, Luke, and Daniel.[22][24] They live in Cheshire.[25]

      John Bishop enjoys playing football and is an avid Live etc….

      Looking at making the first ‘ 2 words’ of a paragraph style grep character style.

      Am I missing something?

    • #82812
      Peter Kahrel
      Participant

      Only after copying your sample did I discover what went wrong. (It did work, by the way, but not correctly — it’s always helpful to indicate in what way something doesn’t work.) Your sample has a return between the two paragraphs and a space before that return, so in the expression I gave started matching the return and/or rogue space character. This expression should fix that:

      ^(.+?)(.+?)(?=)

      stands for ‘horizontal space’, so it matsches all spaces except the hard return. And I added (?=) so that the expression doesn’t match the space after the second word.

      P.

    • #82813
      Paul White
      Member

      Hi Peter I don’t doubt you one bit… but for some reason either one works in my document?

      ???

      Can i send you the file just in case I am being a dumb a%$$?

    • #82816
      Scott Rudy
      Participant

      thanks for piggybacking on my post….i tried out peters grep and it works like a charm, this is one i will be writing down for some other use

      and , peter thanks for spelling out what the different codes mean, it really helps me wrap my head around this

      scott

    • #82818
      Paul White
      Member

      No probs Scott.

      I thought it related similar to your original question.

      However, just tried it in a clean document and still can get it to work :(
      The reasoning for the code does help, some of which I have never seen before. So thank you.

    • #82819
      Scott Rudy
      Participant

      what response are you getting when you assign the paragraph style, which has the grep assigning the character style, to the text?

    • #82839
      Peter Kahrel
      Participant

      Paul,

      > but for some reason either one works in my document?

      I guess you meant ‘neither’ :)

      Before sending any files, could you tell me what goes wrong? When you enter the GREP expression in the Find What field of the GREP tab (you are using the GREP tab aren’t you?) and click the Find button, what happens?

      1. InDesign shows an alert saying ‘Cannot find match’.
      2. InDesign finds something, and highlights it, but it’s not what you expected or intended.

      Please be clearer about ‘It doesn’t work’.

      Peter

    • #82850
      Paul White
      Member

      Sorry Peter for not being clear on whats happening.

      I know how grep works and how to test it, I just don’t know enough how to write the code.

      I did do I a find and replace [grep tab] and its highlights the text’, I did copy the text from this thread back into the document as I know you used this to create the code.

      Just to be sure I copied the text into my grep document which as a paragraph styles with working grep codes attached, just to check it wasn’t a document issue.

      I even checked there was no character style active which I know sometimes overrides the paragraph styling. I am at a bit of a loss

      its a shame I can’t attach a screen shot!

    • #82851
      Paul White
      Member

      Just found the problem after I sent the last message.

      When I copied the code from this site it must of add a space at the end or something. If I delete anything after the last character of the code including the last ) and re-enter ) after the then it works.

      Even the first code

      ^(.+?)(.+?)

      works now.

      Strangely, when I copied your code yesterday and used the grep tab is was erroring on cannot find match. Sorry for being a pain but got there in the end and is now in my bank of useful grep codes.

      Just so I know to do 3 words its

      ^(.+?)(.+?)(.+?)(?=)

      thanks for your help Peter

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