Reputation: 3000
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
Upvotes: 4
Views: 17393
Reputation: 10220
This will remove anything between ab
.
replaceAll("ab([;\s\w\"\=\,\:\./\~\{\}\?\!\-\%\&\#\$\^\(\)]*?)ab","");
Please add any special character, if I'm missing it.
Upvotes: 2
Reputation: 22616
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 *", " ")
Upvotes: 11