假设我有这个字符串:
foo = "This is a string 'with a string inside it!'"如何提取“里面有一个字符串!”来自foo
发布于 2013-05-19 02:10:31
foo = "This is a string 'with a string inside it!'"
foo[foo.index("'")..foo.rindex("'")]
#=> "'with a string inside it!'"发布于 2013-05-19 02:11:07
foo[/('.+')/, 1]
=> "'with a string inside it!'"这是在使用regular expression。此特定语法返回第一个匹配项。
发布于 2013-05-19 03:25:16
使用非贪婪量词
foo[/'.*?'/]https://stackoverflow.com/questions/16627392
复制相似问题