且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ruby中使用gsub regex

更新时间:2023-09-01 18:13:04

我会做这样的事情:

value = 'localhost:8393/foobar/1 test:foobartest'

value.split.first
#=> "localhost:8393/foobar/1"

或者如果您想使用正则表达式:

Or if you want to use an regexp:

value.sub(/ test.*/, '')
"localhost:8393/foobar/1"