Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ruby - Getting specific sections from a string

Posted on 2011-03-16
3
Medium Priority
?
388 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
[X]
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
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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 …
Six Sigma Control Plans

636 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