我已经在R中解决了以下文字。 有谁知道如何用Ruby编写它?
text <- 'have a nice day, @hello, mr burs'
x <- gsub('.*(@\\w+).*', '\\1', text)
x
[1] "@hello"
谢谢!
答案 0 :(得分:1)
s = 'have a nice day, @hello, mr burs'
s =~ /.*(@\w+).*/ # match
$~[1] # this will return "@hello"
# $~ means "the last regexp match", a `MatchData` instance. And we can get matched group by index.