Ruby正则表达式-gsub是否存储匹配的内容? [英] Ruby regex- does gsub store what it matches?
本文介绍了Ruby正则表达式-gsub是否存储匹配的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用
.gsub(/matchthisregex/,"replace_with_this")
gsub是否将与正则表达式匹配的内容存储在某个地方?我想在替换字符串中使用匹配的内容.例如类似
does gsub store what it matches with the regex somewhere? I'd like to use what it matches in my replacement string. For example something like
"replace_with_" + matchedregexstring + "this"
在我上面的示例中,matchedregexstring是gsub存储的匹配项吗?抱歉,这令人困惑,我不知道该怎么说.
in my above example where the matchedregexstring would be the stored match from gsub? Sorry if that was confusing, I don't know how else to word that.
推荐答案
查看全文