Solved

Ruby - Getting specific sections from a string

Posted on 2011-03-16
3
379 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
word0 challenge 3 90
Program to display an alert on Windows Toolbar 2 76
Scripting vs. Programming languages 25 165
Please help| Getting the syntax error in below query. 2 56
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
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.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 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

13 Experts available now in Live!

Get 1:1 Help Now