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

Need to extract string via Regex

I have data looking like that:
#<Twitter::Tweet:0x00000001b63bd0 @attrs={:created_at=>"Thu Dec 05 07:06:26 +0000 2013", :id=>408492543140036608, :id_str=>"408492543140036608", :text=>"\"..and so on

I need to get all characters following @attrs= so basically starting with the curly brackets till the end of the string. Any help is appreciated. (I will use it in a Ruby script)
0
Nikolai_Manek
Asked:
Nikolai_Manek
1 Solution
 
Terry WoodsIT GuruCommented:
Not sure of the Ruby syntax, but try using pattern:
(?<=@attrs=).*
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I have added the "Ruby Scripting Language" topic area to your question.

mccarl   --   Topic Advisor
0
 
Geert BormansCommented:
this would be your regex

/^.*.@attrs=(.+)$/

use it

mytext = '#<Twitter::Tweet:0x00000001b63bd0 @attrs={:created_at=>"Thu Dec 05 07:06:26 +0000 2013", :id=>408492543140036608, :id_str=>"408492543140036608", :text=>"\"..'

puts mytext.gsub(/^.*.@attrs=(.+)$/, '\1')

Open in new window

0
 
Nikolai_ManekAuthor Commented:
Thank you very much. Works like a charm.
0

Featured Post

Industry Leaders: 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!

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