• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

Ruby - Getting specific sections from a string

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
Caroline_Swart
Asked:
Caroline_Swart
  • 2
1 Solution
 
lusfernandosCommented:
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
 
JESiiCommented:
Try this:
result = dllEntries.grep(/^HKEY/)
puts result
output = result.map { |e| e.match(/(^.*})/)[0] }
puts output

Open in new window

0
 
JESiiCommented:
Glad that worked out; thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now