Reputation: 563
puts myvalue[1]
(my value is a String)
#My COmments
#Checked on 54
[Roll]
new line = see, that, cfiu\poli
check_that = roll\uiju, rolldeny that, its=oik, mao\ikir4
stares = roll\okik, roll\asde4, roll\kz98e
I'm trying to extract after Roll and assign in to an array
groups = myvalue[1].match(/^[Roll].*/)
Output I got
new line = see that cfiu\poli
instead of (expected one)
new line = see that cfiu\poli
check_that = roll\uiju, rolldeny that, its=oik, mao\ikir4
stares = roll\okik, roll\asde4, roll\kz98e
How to do it, thanks
Upvotes: 0
Views: 48
Reputation: 10251
> string = "String begins here
[Roll]
new line = this is new line content
check_that = check that line content
stares = stares content"
> required_string = string.split("[Roll]").last.strip
# new line = this is new line content
# check_that = check that line content
# stares = stares content
> first_arry = required_string.split("\n").map{|e| e.split("=")}.map(&:first)
#=> ["new line ", "check_that ", "stares "]
> second_arry = required_string.split("\n").map{|e| e.split("=")}.map(&:last)
#=> [" this is new line content", " check that line content", " stares content"]
Upvotes: 1
Reputation: 3264
Change your groups assign line to this:
groups = myvalue[1].partition(/\[Roll\]/).last
Upvotes: 1