Reputation: 903
I'm searching for a method in ruby-on-rails what give content between special chars. EX:
"This is my string, and < this is the content >"
expect result between < >, "this is the content"
Upvotes: 2
Views: 63
Reputation: 96
You can use the regular expression /<(.*?)>/
str = "This is my string, and <test one> < test two >"
str.scan(/<(.*?)>/)
=> [["test one"], [" test two "]]
Upvotes: 3
Reputation: 952
You want a non-greedy capture. This is the regular expression:
<(.*?)>
See it here: http://rubular.com/r/7KN1HLipyW
ie
"This is my string, and < this is the content > and <another one>".scan(/<(.*?)>/)
Upvotes: 0
Reputation: 5778
Try this regexp:
"This is my string, and < this is the content > <and more content>. And the tail".scan(/<.*>/)
It gives you an array of occurrences:
=> ["< this is the content > <and more content>"]
Upvotes: 1