Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem regarding filtering text between 2 words, the string that I'm trying to filter looks like this:

Word 1
   this is text
   more "text"
   this is more text
 end
 Word 3
   this is more text
   more "text"
   this is more more text
 end

What I am trying to do is filtering the pieces of the text between "Word" and "End" and put them seperatly in an 2d array like so

array = [["this is more text /n more "text" /n this is more text"]["this is more text /n more "text" /n this is more more text"]

What I have now atm is this:

test = []
result = string.san(/Words.(.*?)end/m)
res.each do |r|
   test.push(r[0])
end
return test

Any help will be greatly appreciated Kind regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
154 views
Welcome To Ask or Share your Answers For Others

1 Answer

input.scan(/(?<=Wordsd).*?(?=end)/m).map &:strip
#? [
#  [0] "this is text
   more "text"
   this is more text",
#  [1] "this is more text
   more "text"
   this is more more text"
#]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...