Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP query to change space to tab

Advocate ,
Jul 19, 2018 Jul 19, 2018

There are many paragraphs and at the beginning of each paragraph, there are one or two characters (they could be letters or numbers or a period) followed by a space, an = sign and a space, and then any number of more characters.

I need to change the space to tabs.

For example the original text has a space character before and after the =

AB = Blah blah blah

needs to change to this where there is a tab character before and after the =

AB     =     Blah blah blah

Anyone know a GREP find/change query for this?

TOPICS
Scripting
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 20, 2018 Jul 20, 2018

For 1:

^[\w.]+\K *= *

replace with \t=\t

This looks for any sequence of letters or numbers (\w, "word" characters, which include uppercase and lowercase as well as digits, and the underscore for historical reasons) or a period at the start of a paragraph, then discards what it found. It then matches zero or more spaces, the equals, and optionally more spaces. This latter part gets replaced with a tab, equals, tab.

For 2:

^[\u\l]\.\K +

replace with a single tab. This looks for 'any letter' (one of uppe

...
Translate
Advocate ,
Jul 19, 2018 Jul 19, 2018

I also need a GREP query to change multiple spaces to a single tab character.

For example: with multiple spaces after the A period:

A.   Blah blah blah

need to change to a single tab instead of multiple spaces after the A.

A.     Blah blah blah

The letter would not necessarily be an 'A', it could be any letter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2018 Jul 20, 2018

For 1:

^[\w.]+\K *= *

replace with \t=\t

This looks for any sequence of letters or numbers (\w, "word" characters, which include uppercase and lowercase as well as digits, and the underscore for historical reasons) or a period at the start of a paragraph, then discards what it found. It then matches zero or more spaces, the equals, and optionally more spaces. This latter part gets replaced with a tab, equals, tab.

For 2:

^[\u\l]\.\K +

replace with a single tab. This looks for 'any letter' (one of uppercase or lowercase), followed by a period. Then it discards this, matches any positive number of spaces, and these get replaced with your tab again.

I used the fairly new addition "\K" in both expressions because the alternative is to construct elaborate lookbehind expressions -- quite basic for #2, but barely doable for #1 (it is do-able but this is so much easier).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 20, 2018 Jul 20, 2018
LATEST

Thank you for this, Jongware -- you are truly the best!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines