-1

I know this is difficult for notepad but I still wanted to ask if you could help me!

my job needs to put a lot of people with the same address together to save data, I still do it by hand every day but a large number makes Me want to find another way.

For example:

John Stave
Amazon Inc
Michigan, Mi.

Elon Mask
Amazon Inc
Michigan, Mi.

To get this:

John Stave, Elon Mask, Amazon Inc, Michigan, Mi.

Which means I will match people with the same address.

InSync
  • 4,851
  • 4
  • 8
  • 30

1 Answers1

1

I agree with InSync: a script in some programming language is better suited to solve this task.

If you insist on doing it by hand, you can use regex ^(.+)(\n.+\n.+)([\s\S]*?)(.+)\2$ with replacement $1, $4$2$3. It will merge nearest two blocks with the same company and location. You'll need to repeatedly use this replacement until anything is merged.

Later to convert blocks of three lines into single line delimited by , you can use (.+)\n(.+)\n(.+)(\n|$) with replacement string $1, $2, $3. Use this replacement only once.


Explanation:

  • Merging with ^(.+)(\n.+\n.+)([\s\S]*?)(.+)\2$, demo can be seen here:
    • (.+) matches name line of the first merging block, will be referenced as $1 in replacement string,
    • (\n.+\n.+) matches company and location block of merged block, will be referenced as $2 in replacement string and \2 in backreference matching later,
    • ([\s\S]*?) matches anything, for cases when merged blocks are not consequent, will be referenced as $3 in replacement string,
    • (.+) matches name of second merged block, will be referenced as $4 in replacement string,
    • \2$ matches company and location of second merged block if it is exactly the same as of the first one.
  • (.+)\n(.+)\n(.+)(\n|$) matches blocks of three non empty strings, followed by newline or end of file. Demo can be seen here.

Also it is recommended to look through this nice reference on What does this regex mean.

markalex
  • 8,623
  • 2
  • 7
  • 32
  • Thank you. but I can't use them for my notepad, the result is not like your example, I don't know why, My notepad version is 8.4 – Vuvanvui Vui Apr 13 '23 at 03:27
  • @VuvanvuiVui, sorry, I don't have notepad++ at hand, so tested it in vscode. I've checked documentation, and yes, this wouldn't work(. I believe you can't solve this task in notepad++ with regex due to limitations of its regex engine. Could you use vscode or sublime? – markalex Apr 13 '23 at 04:59
  • sorry, I'm using notepad only, thankyou. – Vuvanvui Vui Apr 13 '23 at 04:59