Grep – find second word in Par

Home Forums General InDesign Topics Grep – find second word in Par

This topic contains 4 replies, has 2 voices, and was last updated by  ohad nanach 4 years, 11 months ago.

  • Author
    Posts
  • #75082

    ohad nanach
    Member

    Hi all,

    I need help finding the second word in each paragraph with grep.

    Thanks in advance

  • #75084

    Aaron Troia
    Member

    That’s a tough one Ohad, there are many variables both before and after both the first and second words to account for, but this is what I came up with so far, it still doesn’t catch every second word but it’s a start.

    ^[^ ]+ \K\w+([’\w]+)?(?=[,])?

  • #75087

    ohad nanach
    Member

    Hi Ron,
    I basically need to insert an anchored object (which is copied to the clipboard) right before the 3rd word in the paragraph.
    does it make it simpler for you? thanks

  • #75089

    Aaron Troia
    Member

    Ohad, that does make it easier, I thought you were trying to isolate the second word, but that extra bit of information really helps. So depending on whether you want to place the anchored object before or after the space after the second word,

    before the space:

    Find: ^([^ ]+ [^ ]+)(?= )
    Replace: $1~c

    or after the space:

    Find: ^([^ ]+ [^ ]+ )
    Replace: $1~c

    Let me know if that works or not for you.

  • #75090

    ohad nanach
    Member

    That works great! Thanks much for your help ++

You must be logged in to reply to this topic.