Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Ruby - Getting specific sections from a string

Posted on 2011-03-16
3
380 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
ID: 35148729
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
ID: 35152611
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
ID: 35189077
Glad that worked out; thanks for the points!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

792 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