Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 ruby 代码中的单独变量中提取乘客版本
pasver = %x[/usr/local/rvm/bin/gem list | grep passenger | sed -r 's/(passenger ()(.*)())/\2/]
更新:::
我的解决方案:
pasver = `/usr/local/rvm/bin/gem list | grep 乘客`.sub /.*\((.*)\).*/, '\1'
简单的正则表达式:
passenger *\(([^)]+?)\)
将接受括号中的所有内容
您可以从 Ruby 中获取 gemspecs 列表,您可以从中轻松提取版本号:
Gem::Specification.find_all_by_name("passenger").map(&:version).map(&:to_s)