Searching and copying multi-line strings

Help with writing and running scripts

Searching and copying multi-line strings

Postby lm77054 » Sat Jul 21, 2012 9:24 am

Hi all:

I hope someone can help me. I'm trying to extract repeative, multi-line keys from a *.REG file. Specifically, the e-mails. Now I've seen the post Convert REG_MULTI_SZ hex to text, and that will work just fine, once I get the lines out. Here is what I want to do

============= Begin "Cut down registry entries"

"Account Name"= (hex strings like in the above post,some multi-line)
"SMTP Use Auth"=(dword value)
"Display Name"= (hex strings like in the above post,some multi-line)
"Email"= hex:ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00
"POP3 Server"= (hex strings like in the above post,some multi-line)
"SMTP Server"= (hex strings like in the above post,some multi-line)
"POP3 User"= (hex strings like in the above post,some multi-line)
"POP3 Password"= (hex strings like in the above post,some multi-line)

============= End "Cut down registry entries"

Of cource, the email entry above isn't a valid e-mail.

What I'd like to do, is to extract the lines within the "Email=" area, in this case:

"Email"= hex:ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,\
ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00,ff,00

Then put them into a new file, search and replace "Email"= hex: with nothing. After that, I will then run the script from "Convert REG_MULTI_SZ hex to text" manually.

I tried to find an example of the finding of the strings, and copying them, but I couldn't (maybe I had a brain fart). But any help would be greatly appreciated.

I have a large number of e-mails, and by extracting the entries from the registry makes it easier to see what, if any is missing.

THANKS LOADS IN ADVANCE!
lm77054
Basic User
Basic User
 
Posts: 16
Joined: Sat Feb 26, 2011 12:11 pm

Re: Searching and copying multi-line strings

Postby Mofi » Sat Jul 21, 2012 3:59 pm

Well, this is an often required task and therefore there are a lots of macros and scripts showing how to do this. Scripts section on Extra Downloads page contains a reference to Filter lines script. There is also findMultiline.js on server of IDM not referenced on the downloads page. Well, this second script is just a very small script template and not a ready to use script. So I decided to quickly write this simple script exactly for what you need.

Code: Select all
if (UltraEdit.document.length > 0) {

   // Define all parameters for the case-sensitive Perl regular expression
   // search used to find email address registry entries in active file.
   UltraEdit.perlReOn();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
      UltraEdit.activeDocument.findReplace.searchInColumn=false;

   // Set caret to top of active file and prepare user clipboard 9 for the data.
   UltraEdit.activeDocument.top();
   UltraEdit.selectClipboard(9);
   UltraEdit.clearClipboard();

   // Run the search in a loop until no email address block could be found anymore.
   // Append to clipboard always all found characters selected in file except the
   // first 13 characters which are  "Email"= hex:  not interested in.
   while (UltraEdit.activeDocument.findReplace.find('^"Email"= hex:[0-9a-f][0-9a-f,\\\\\\r\\n]+')) {
      UltraEdit.clipboardContent += UltraEdit.activeDocument.selection.substr(13);
      // For making it easier in new file to see where a block begins append an extra line termination.
      UltraEdit.clipboardContent += "\r\n";
   }
   // Paste the found blocks into a new file if a block was found at all.
   if (UltraEdit.clipboardContent != "") {
      UltraEdit.newFile();
      UltraEdit.activeDocument.paste();
      UltraEdit.activeDocument.top();
      UltraEdit.clearClipboard();
   }
   // Make the Windows clipboard active again.
   UltraEdit.selectClipboard(0);
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts