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

How to change 'space' to 'tab' with GREP

Tagged: 

Return to Member Forum

  • Author
    Posts
    • #34074

      I’m trying to change all ‘spaces’ which come after a ‘number followed by a period’ to ‘tabs’. Therefore I searched for
      (\d+\.)
      and then replace it for

      but that way the ‘number followed by a period’ is gone and only the ‘tab’ is left.

    • #34075

      It does exactly what you ask: if you press the Find button, you will see it highlights the digit(s), period, and space. That is what gets replaced with just the single tab in your Replace field.

      There are two straightforward solutions. You already bracketed the not-to-be-removed part of the expression, so you can “recall” that in the Replace field using “$1”:

      $1

      A slightly better way is not to highlight the digit at all and only change the actual space to a tab. Search for this:

      (?<=\d\.)

      and replace with just a single tab. This looks for a space which *must be preceded* by a single digit and a period (so these are *not* included in the found expression). Then only the space gets changed. This is ‘better’ in the sense that it’s best to replace only what needs to be changed; in this case, the space itself.

      A note: is not really just a space, it’s all kinds of spaces. That sounds ideal, except that this also considers both the hard return and the soft line break as “space”. So in this case, you might be changing hard returns to tabs as well.

      Then again, maybe that’s exactly what you want :)

      If not, you can build a list of space types you *do* want to change. Use this: [ ~S] instead of the single code . This is “tab, space, unbreakable space”; you can add all other space codes you think you may need.

      • #34089

        Thanks! This works very well.

        Mentioning the space, I looked for a normal space in the Find/Change dialog but couldn’t find it. Thats why I used any space ?

    • #102727
      Kiran Kumar
      Member

      I need to find all the numbers followed by dot(.) and then tab. To that , need to provide left Indent.
      eg : 1. Some text goes here.

      I have tried with the Find/Change using GREP (\d+\.+) , still i am not getting the result.

      app.findGrepPreferences.findWhat = “(\d+\.+)”;
      alert(app.activeDocument.findGrep().length);

      Output : 0
      Always getting 0

      Correct me if i am wrong with GREP.

      Thank you in advance

    • #102728
      Peter Kahrel
      Participant

      …findWhat = “d+.t”;

      You have to double the backslashes. There’s no need for the parentheses.

      And it might be a good idea to start a new topic for a new query.
      And since this query is a script problem, ask the question in the scripting forum.

      P.

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