regex to reorder text with MS Word 2010 or Notepad

2019-08-06 22:50发布

问题:

I'm trying to figure out how to convert a long document, styles as a dictionary.

I have this:

÷H1.
John.
walks,
drives,
eats,
drinks,
flies,
travels,

÷H2.
Peter.
flies,
rides,
swims,

÷H3.
James.
laughs,
cries,

I need it like this:

÷H1. John. walks,
÷H1. John. drives,
÷H1. John. eats,
÷H1. John. drinks,
÷H1. John. flies,
÷H1. John. travels,

÷H2. Peter. flies,
÷H2. Peter. rides,
÷H2. Peter. swims,

÷H3. James. laughs,
÷H3. James. cries,

Thank you! Alex

回答1:

Steps in notepad++ with regular expressions checked:

  1. Find: (÷[^.]+\.)[\r\n]+([^.]+\.)

    Replace: $1 $2

  2. Find: (÷[^\r\n]+.)[\r\n]{1,2}([a-z]+,)

    Replace: $1 $2

  3. Find: ((÷[^\r\n,]+\.)[^\r\n]+[\r\n]{1,2})([a-z])

    Replace: $1$2 $3

Repeat step 3 as many times as necessary.