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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With