There is a text of about 1000 characters.
String text = "bla bla..................
.........................
.........................
file.....................
.........................
.........................
file.....................
.........................
Some lines start with a word "file". How can I remove ALL such lines? Here is what I tried
text = text.replaceAll("file.*?//n", "");
The line break can be removed from string by using str_replace() function.
Use replaceAll() method to remove backslash from String in Java. It is identical to replace() method, but it takes regex as argument. Since the first argument is regex, you need double escape the backslash.
You could try the following instead:
text = text.replaceAll("(?m)^file.*", "");
(?m)
: Turns multi-line mode on, so that the start-of-line ^
anchor matches the start of each line.^
: matches the start-of-line.file
: Matches the literal file
sequence..*
matches everything to the end of line.So this look for any line that has the word file
at the start, then matches the entire line and replaces it with the empty string.
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