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

Add (the same) 2 letters to every instance of 4 digits in a 45 page document

Return to Member Forum

  • Author
    Posts
    • #95135
      Tabrez Ahmad
      Member

      Hi all

      I’ve a GREP question which I can’t find the answer to.

      Basically, I’ve got a 45 page document filled with various instances of 4 digit numbers, for example, 5137, 5138, 5139 and so on.

      All I need to do is add the letters PJ before each of these instances.

      What GREP expression would I use?

      Thanks in advance!

      Tabrez :)

    • #95138

      Hi,

      try:

      Find what: \d{4}
      Change to: PJ$0

      Kai

    • #95139
      Tabrez Ahmad
      Member

      Can I say that I love you Kai?

      Thanks so much!

      If it’s not too much trouble, to help me understand for future ref, how DID that work?

      Thanks again!

      Tabrez

    • #95140

      \d is a so called wildcard-metacharacter and will find all digits [0-9]. To find one or 50 you could use \d+. The plus-symbol is the metacharacter for one or more times. But you ordered a specific amount of digits: 4 > Therefore I use \d{4}. Because this will find also 4 digits in a 6 digits number, I use a so called anchor: (for word boundary).

      \d{4}

      Find the start of a number, 4 digits, end of a number. You can then insert everything with $0 in the change to field.

      Kai

    • #95141
      Masood Ahmad
      Participant

      Let me try to explain on behalf of Kai.

      The Find What :

      stands for Word Boundary i.e it will not search for string that is part of a long string. for example it will not search for 5 digit number or “xyz1234”. In your case the numbers are in group of 4.
      \d stands for any Digit
      {4} stands for the length of the previous GREP Wildcard which is \d. The 4 digits numbers can also be expressed as \d\d\d\d
      stands for Word Boundary

      The Change to:

      PJ stands for the replacement character as per your choice.
      $0 stands for Find Text i.e. replace what is being find through the Find What expression.

      Hope that helps.

    • #95145
      Tabrez Ahmad
      Member

      Thanks to both of you, massively helpful!

      All the best from sunny London! :)

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
Forum Ads