3

is it possible to replace every 4 Lines the Break to a Tab in UE or NPP with a regex search/replace?

File before:

    #12
    ab
    cde
    ef
    #34
    ghij
    ijk
    kl
    #5678
    uv
    w
    xyz
...

should be after replace

#12 ^t ab ^t cde ^t ef
#34 ^t ghij  ^t ijk ^t kl
#5678 ^t uv ^t w  ^t xyz
gsxr1300
  • 351
  • 2
  • 4
  • 12

2 Answers2

5

Here is a way to do the job:

Find what: (.+)\R(.+)\R(.+)\R(.+\R)?
Replace with: $1\t$2\t$3\t$4

Check Regular Expression
DON'T check dot matches newline
and click Replace All.

Explanation:

(.+)\R   : Capture in group 1 everything until a line break (excluded)
(.+)\R   : Capture in group 2 everything until a line break (excluded)
(.+)\R   : Capture in group 3 everything until a line break (excluded)
(.+\R)?  : Capture in group 4 everything until a line break (included), optional

\R stands for any kind of linebreak (ie. \r or \n or \r\n)

Toto
  • 89,455
  • 62
  • 89
  • 125
2

[\n\r](?!#) Will do and replace by \t

It will replace crlf if not followed by a # by tab when using windows encoding. (?!#) is a negative lookahead which exclude any \n or \r followed by a # (on next line)

Beware it will leave a space before the tabs, if you really wish only tab between each field you may have to change encoding to have only \n or \r (linux or mac).

Tensibai
  • 15,557
  • 1
  • 37
  • 57
  • @Surinderツ As far as I understood, #123 has not to be moved, just the following lines. Replacing the carriage return by tab (unless the last one) makes lines starting by #123. I edited to explain the regex (forgot it, sorry) – Tensibai Sep 02 '14 at 12:06