开发者

regex remove everything between 2 strings

I need a regex for my replaceAll that removes everything between 2 strings and the strings themselves.

For example if I had something like.

stackoverflow is really awesome/nremove123/n I 开发者_如何学编程love it

I was trying to do a replaceAll like this line.replaceAll("/n*/n", ""); This should result in

stackoverflow is really awesome I love it

I thought the asterisk meant anything but can't get it to work?

cheers


No, the . means any character. * means any number of the previous things. So anything is .*. What you need is

/n.*/n

If you want to leave an empty space between words use this instead

replaceAll("/n.*/n *", " ")


I think you need a dot:

replaceAll("/n.*/n")


This will remove anything between ab.

replaceAll("ab([;\s\w\"\=\,\:\./\~\{\}\?\!\-\%\&\#\$\^\(\)]*?)ab",""); 

Please add any special character, if I'm missing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜