0

I'm trying to search through text in Notepad++ for certain "line pairs" (lineA, lineB) to concatenate them and discard anything else.

Each Line Pair

  1. lineA must contain a comma
  2. lineB is the closest line that follows lineA while also containing the word "Proximity"

Sample Text

1   "SCOTT, Michael"  
2   "Office Manager"  
3   "Card Number Card Format Disabled"  
4   "0273ADNC PAC Proximity Reader False"  
5   "Random rubbish"  
6   "SCHRUTE, Dwight"  
7   "Card Number Card Format Disabled"  
8   "0897FFRF PAC Proximity Reader False"  

Concatenated Text:

1   "SCOTT, Michael;0273ADNC PAC Proximity Reader False"  
2   "SCHRUTE, Dwight;0897FFRF PAC Proximity Reader False"  
  • concatenated lines are delimited with a semicolon to help me parse them later
  • extra lines 2, 3, 5, and 7 from "Sample Text" were discarded

1 Answer 1

2

Not sure if it's the cleanest ideas... but it does work.

First find (all lines not containing either a comma or the work Proximity:

^((?!,|Proximity).)*$\R

And replace with nothing.

Then find:

^("[A-Z]+,\s[A-Za-z]+)"$\R^"(.*Proximity.*")

And replace with:

\1;\2

enter image description here


Or you can first do a find for:

^("[A-Z]+,\s[A-Za-z]+)"$\R(^.*\R?^.*\R?^.*\R?^.*\R?^.*\R?^.*\R?^.*\R?)^"(.*Proximity.*")

Replace with:

\1;\3

This will merge the name line with the card number line. Then find all lines without a comma and replace with nothing:

^[^,]*$\R

enter image description here

2
  • OMG, you are genius, it totally worked. Thank you!!
    – dakim
    Apr 18, 2023 at 19:44
  • beautiful answer even though it isn't the "cleanest". +1. Apr 18, 2023 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .