2

Here's what I'm looking to do with the following code:

;"0";"<br>Address: 999 Murrica Avenue Washington D.C.<br>Contact:";"";"";"LAYER";"4";"AHA";"925";"px";"500";"";"0";"0";"Cs";"41707.4695717593";"Cs";"41707.4695717593";"0";"0";"ADDY";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";;"0"

Ideally I'd like to be able to perform a search for ADDY and replace it with the string that is between "Address: " and "(br)Contact" so that the end result would resemble this:

Please note that the BR before Contact is HTML for a line break

;"0";"<br>Address: 999 Murrica Avenue Washington D.C.<br>Contact:";"";"";"LAYER";"4";"AHA";"925";"px";"500";"";"0";"0";"Cs";"41707.4695717593";"Cs";"41707.4695717593";"0";"0";"999 Murrica Avenue Washington D.C.";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";;"0"

I've tried search and I have stumbled across this article which seems to do something similar to what I want, I just can't seem to figure out how to modify the expression to work for me. I have about 200 instances, each on their own line, that I need to do this to.

This is my first post so hopefully I've written it clear so that it will be easy to understand, thanks in advance!

Article Link - Can notepad++ regex find a string and replace with a new string that contains the found string

Update - Adding another example of the code

0000;"Name";"<br>Address: 9904 Coliseum Blvd Fria, AL 78903 <br>Contact: Joe Joe<br>Phone: 123-123-1234 <br><a href='mailto:asdfasfd@jfsdofj.com" title='Click to send a message'>Email</a><br>Type: Associated with the <a href='http://www.sdafsfs.org'>Association</a>.";"0";"ADDY";"";"";"LAYER";"4";"A.png";"925";"px";"500";"map";"0";"0";"Cs";"41707.4695717593";"Cs";"41707.4695717593";;"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";"0";;"0"

Update- Tim's modified expression results in this output (He's getting there!)

0000;"Name";"<br>Address: 9904 Coliseum Blvd Fria, AL 78903 <br>Contact: Joe Joe<br>Phone: 123-123-1234 <br><a href='mailto:asdfasfd@jfsdofj.com" title='Click to send a message'>Email</a><br>Type: Associated with the <a href='http://www.sdafsfs.org'>Association</a>.";"0";"9904 Coliseum Blvd Fria, AL 78903 ADDY
Community
  • 1
  • 1

2 Answers2

2

Press CTRL + H and type the following into the "Find what" box:

(.*Address: )(.*)(<br>Contact.*)(ADDY)(.*)

Then type the following into the "Replace with" box:

$1$2$3$2$5

Make certain that your search mode is set to "Regular expression" or else Notepad++ will treat the regex as a literal string (and it won't work).

The Stack Overflow article which I think would have helped you the most is here. It shows how to use regex capture groups in Notepad++, and this is what will allow you to make the replacement you want.

Community
  • 1
  • 1
Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
  • Thanks for the fast response, Tim! Unfortunately whenever I input your code into my find and replace it says that it is unable to find the text. Also, I started playing around with your code to see if I could dissect it and understand it better in hopes it would work with a few tweaks, but I just learned what regex was a few hours ago so I'm still new to this. – Christopher Feb 17 '16 at 04:46
  • Did you set the search mode to regular expression? I tested my answer in Notepad++ using your sample data and it worked. – Tim Biegeleisen Feb 17 '16 at 04:47
  • I did and it appears to attempt to work on one line, but replaces ADDY with too much information. Afterwards whenever I press the "find" button again it can't locate anymore instances. – Christopher Feb 17 '16 at 04:53
  • Update your question showing us more data. My answer will work for the sample you have given us. – Tim Biegeleisen Feb 17 '16 at 04:54
  • I updated my answer to handle the new data. If there are still other edge cases you need to handle, then I would advise you to show us the full range of possible inputs. – Tim Biegeleisen Feb 17 '16 at 05:15
  • Awesome, I appreciate it, Tim! I'll fiddle around with your code for a little bit to see if I can get the desired results. As far as the full range goes, it's a CSV file that has around 218 lines with no telling how many characters on each line. I'm basically wanting to copy the address that is near the beginning of each line and replace the "ADDY" text midway through the line. The address near the beginning will always fall between "Address: " and "(br)Contact:", other than that the characters can change. Not sure if that helps. – Christopher Feb 17 '16 at 05:23
  • If this really be the format then my answer should work for you. – Tim Biegeleisen Feb 17 '16 at 05:23
  • It's almost correct I'm pretty sure, haha. I'll update to show you what your code is putting out. – Christopher Feb 17 '16 at 05:31
0

I'd do:

  • Ctrl+H
  • Find what: (?<=\bAddress: )(.*?)(<br>Contact.*?)(\bADDY\b)
  • Replace with: $1$2$1
  • Replace all

Make sure you have checked Regular expression.

Explanation:

(?<=\bAddress: )    : Positive look behind, we must have Address before
(.*?)               : group 1, everything between (NOT greedy) (ie. the address to duplicate)
(<br>Contact.*?)    : group 2, until first occurrence of <br> followed by Contact
(?:\bADDY\b)        : non capturing group, the string to be replaced
Toto
  • 83,193
  • 59
  • 77
  • 109
  • Thanks for the response! I'm currently in class, whenever I get a chance I'll check this out to see if it works for me. I think the problems are on my side because Tim said that the above code works for him, but yet I'm having issues with it. – Christopher Feb 17 '16 at 14:08
  • @Christopher: The difference is in the NON greedy match – Toto Feb 17 '16 at 14:10
  • I'm going to do an additional search eventually when I'm out of class to learn what the terms greedy and non greedy mean. I'm pretty new to all of this. – Christopher Feb 17 '16 at 14:31