小编Gar*_*ary的帖子

组捕获

大家好,我想弄清楚如何在 kotlin 中使用从正则表达式中捕获的组的结果,而我一生都无法在网上找到任何东西。我基本上只是想简单地去掉“k”

    var line = "4353453555k fgafg 4535k"
    line.replace("(\\d*)[k]".toRegex(), "replace with group capture")
Run Code Online (Sandbox Code Playgroud)

我想要的结果:

    4353453555 fgafg 4535
Run Code Online (Sandbox Code Playgroud)

regex kotlin

4
推荐指数
1
解决办法
916
查看次数

如果使用正则表达式匹配字符串.我可以替换另一条线吗?

如果我使用正则表达式匹配字符串,我可以更改不同行中的字符串吗?基本上,如果foo存在,我想bar改为soap.bar出现在文本文件的不同行上.foo如果存在,将始终出现在之前bar.

while (<FILE>) {
   if (m/foo/){
       s/bar/soap/;
   }
}
Run Code Online (Sandbox Code Playgroud)

数据文件:

foo
food
red
bar
blue
Run Code Online (Sandbox Code Playgroud)

perl

0
推荐指数
1
解决办法
45
查看次数

标签 统计

kotlin ×1

perl ×1

regex ×1