0

我有一个包含以下文本的字符串

String my_string = "hello world. it's cold out brrrrrr! br br";

我想将每个孤立的 br替换为<br />

问题是我想避免将字符串转换为

"hello world. it's cold out <br />rrrrr! <br /> <br />";

我想做的是将字符串(使用replaceAll)转换为

"hello world. it's cold out brrrrrr! <br /> <br />";

我确定这很简单,但我的正则表达式不正确。

my_string.replaceAll("\\sbr\\s|\\sbr$", "<br />");

我的正则表达式应该找到'空白''b''r''空白'或'空白''b''r''行尾'

但它错过了我字符串中的最后一个“br”

"hello world. it's cold out brrrrrr!<br />br"

我究竟做错了什么??TKS!

4

2 回答 2

8
于 2010-10-14T17:20:32.227 回答
0

"hello world. it's cold out brrrrrr!<br />br" Your final 'br' isn't preceded by whitespace. What's supposed to happen?

于 2010-10-14T17:39:39.817 回答