我在python中有以下内容:
regex.sub(lambda t: t.group(1).replace(" ", " ") + t.group(2),string)
Run Code Online (Sandbox Code Playgroud)
其中regex是正则表达式,string是一个填充的字符串.
所以我试图在Scala中使用regex.replaceAllIn(...)函数而不是python 来做同样的事情sub.但是,我不知道如何获得匹配的子组.
group在Scala中有类似python函数的东西吗?
我有一个像这样声明的String列表:
var re1_emoticons=""::Nil
Run Code Online (Sandbox Code Playgroud)
然后我用表情符号(字符串)填写.我试图\\在每个String的开头添加一个re1_emoticons,修改原始的var.
re1_emoticons.foreach(t=>"""\\""" + t)
Run Code Online (Sandbox Code Playgroud)
re1_emoticons.foreach(t=>re1_emoticons.indexOf(t)="""\\"""+ t)
Run Code Online (Sandbox Code Playgroud)
re1_emoticons.foreach(t=>re1_emoticons.indexOf(t):="""\\"""+ t)
Run Code Online (Sandbox Code Playgroud)
但是仍然没有找到方法.有没有正确的方法来做到这一点?