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: To replace 1st instance of a word but ignore next

Tagged: 

Return to Member Forum

  • Author
    Posts
    • #90069
      Paul Williams
      Participant

      Hi,

      I am having a mental block!

      Can anyone show me how, using GREP, I can locate the 1st instance of a word so I can change it but ignore the 2nd instance – but then repeat for next line of text.

      This example shows what I mean:

      Audi A3 1.6 TDI Sportback – 10/60, 59K, FSH, Diesel, 5dr, Blue, Alloys, Radio/CD, Sport Seats, R/L, PAS, Stunning looking Diesel A3 TDI £8,995
      Audi A4 Avant 2.0 TDI Black Edition Quattro – 12/62, 40K, FSH, Diesel, 5dr, Grey, Cruise, Stunning fully loaded Quattro Diesel £19,995
      Audi S3 2.0 TFSI Sportback S-Tronic Quattro Diesel – 10/10, 52K, FSH, 5dr, Purple, Climate, Cruise, Nappa Leather, Great Diesel £16,995

      I need to change the 1st instance of the word ‘Diesel’ on each line to read “<r>Diesel<r>” but ignore the 2nd “Diesel” at the end of the text on each line.

      Please help…..Many thanks in advance. :)

    • #90071

      Hi Paul,

      the first one: ^.+?\KDiesel
      the last one: ^.+\KDiesel

      Find what: ^.+?\K(Diesel)
      Change to: <r>$1<r>

      Kai

    • #90078
      Paul Williams
      Participant

      Hi Kai,

      Thanks for this, but I have a problem.

      I can get this to work fine in the Find/Change box in indesign but can’t get it to function when I use it in a script environment.

      Any ideas as to why this maybe?

      Thanking in you in advance of your plethora of knowledge :)

    • #90079
      Paul Williams
      Participant

      Hi Kai,

      Ignore previous – I realised that I needed to double up on ie ^.+?\KDiesel to ^.+?KDiesel.

      So I needed to escape it with K

      But again, many thanks for your help :)

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