我在ruby-on-rails中搜索特殊字符之间的内容。 EX:
"这是我的字符串,< 这是内容 > "
期待< > 之间的结果," 这是内容"
答案 0 :(得分:3)
您可以使用正则表达式/<(。*?)> /
str = "This is my string, and <test one> < test two >"
str.scan(/<(.*?)>/)
=> [["test one"], [" test two "]]
答案 1 :(得分:1)
试试这个正则表达式:
"This is my string, and < this is the content > <and more content>. And the tail".scan(/<.*>/)
它为您提供了一系列事件:
=> ["< this is the content > <and more content>"]
答案 2 :(得分:0)
你想要一个非贪婪的捕获。这是正则表达式:
<(.*?)>
请在此处查看:http://rubular.com/r/7KN1HLipyW
即
"This is my string, and < this is the content > and <another one>".scan(/<(.*?)>/)