【发布时间】:2012-12-01 04:30:47
【问题描述】:
我正在尝试使用 scala 替换字符串中单词的完全匹配
"\\bhello\\b".r.replaceAllIn("hello I am helloclass with hello.method","xxx")
output >> xxx I am helloclass with xxx.method
我想要的是替换 helloclass 和 hello.method 中的单词是否完全是 hello 而不是 hello
xxx I am helloclass with hello.method
如果输入字符串是
"hello.method in helloclass says hello"
"hello.method says hello from helloclass"
"hello.method in helloclass says Hello and hello"
输出应该是
"hello.method in helloclass says xxx"
"hello.method says xxx from helloclass"
"hello.method in helloclass says Hello and xxx"
我该怎么做?
【问题讨论】: