Solved

Ruby - Getting specific sections from a string

Posted on 2011-03-16
3
377 Views
Last Modified: 2012-06-21
Hi Experts,

I have need to get specific sections from a string in Ruby.
The string is output from a "REG QUERY" command i.e


dllEntries = %x[REG QUERY HKCR\\TypeLib /d /s /f "\"#{dllName}\""]

This returns all the registry entries in HKEY_CLASSES_ROOT\TypeLib for the specified dll.

Output for example looks like this:

HKEY_CLASSES_ROOT\TypeLib\{62419E9D-5D13-4A2D-9043-69518D0DCF85}\2.0\0\win32
  (Default)    REG_SZ    "Path to dll"

HKEY_CLASSES_ROOT\TypeLib\{E19009A2-A258-4DAB-8E92-5A8E49E6C608}\1.0\0\win32
  (Default)    REG_SZ    "Path to dll"

HKEY_CLASSES_ROOT\TypeLib\{E8A97E08-76EF-40B3-B882-40C58B0FFB31}\1.0\0\win32
  (Default)    REG_SZ    "Path to dll"

HKEY_CLASSES_ROOT\TypeLib\{F6581FD0-C5B4-4AA4-9DB9-909ED00E93D5}\1.0\0\win32
  (Default)    REG_SZ   "Path to dll"

End of search: 4 match(es) found.

What I need now is a list (array if possible) of all the registry entry paths so that they can be
deleted with a "REG DELETE" command i.e

1. HKEY_CLASSES_ROOT\TypeLib\{62419E9D-5D13-4A2D-9043-69518D0DCF85}
2. HKEY_CLASSES_ROOT\TypeLib\{E19009A2-A258-4DAB-8E92-5A8E49E6C608}
3. HKEY_CLASSES_ROOT\TypeLib\{E8A97E08-76EF-40B3-B882-40C58B0FFB31}
4. HKEY_CLASSES_ROOT\TypeLib\{F6581FD0-C5B4-4AA4-9DB9-909ED00E93D5}

Any ideas how this can be achieved using ruby string manipulation?

Thanks in advance!


0
Comment
Question by:Caroline_Swart
  • 2
3 Comments
 
LVL 2

Expert Comment

by:lusfernandos
Comment Utility
Hi I don't know what the return type is, however if it is a string, perhaps you could just split using a blank " " and get the first element.

something similar to this:  

def first_name(full_name)
    return full_name.split[0]
end
0
 
LVL 12

Accepted Solution

by:
JESii earned 500 total points
Comment Utility
Try this:
result = dllEntries.grep(/^HKEY/)
puts result
output = result.map { |e| e.match(/(^.*})/)[0] }
puts output

Open in new window

0
 
LVL 12

Expert Comment

by:JESii
Comment Utility
Glad that worked out; thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now