I would like to remove all substrings from a string in java that begin with a specific text and end with a specific text (example )
so i would like to remove
<tag> And everything in between </endTag>
I have end line characters in between the tags.
There are multiple things i want to remove but one of them begins with
WHAT DO YOU WANT TO KNOW ?
and ends with
<end>
I have tried
text = text.replaceAll("WHAT DO YOU WANT TO KNOW \\?.*?<end>", "");
but it didnt work
text = text.replaceAll("CHAPTER 18" , ""); works
Here is a chunk (just an example there are more of those) of text that i want to replace (it is an exert from a book from human sexuality calss so dont read it if you feel uncomfortable but i feel like there isnt anything in it that is inappropriate)
(Tons of text here) WHAT DO YOU WANT TO KNOW ?
Most kids today know all about sex at an early
age. So why are people so uptight about
showing nudity on television? What do they
think it will do to their kids?
Even in a society like ours, which has begun to discuss sex
more openly, it is still a diffi cult subject for children to
understand. Many parents believe that it is their job to
introduce the topic to their children, to explain it to them,
and to teach their children whatever values the parents
believe are appropriate. This may be undermined when
children see fairly uncensored sexuality on television, which
is usually shown without any discussion of values and
without any way to address the children’s questions about
what they are seeing. In the accompanying Sex in Real Life,
“Generation M,” we talk about research on the media
consumption habits of children and teenagers.
REALResearch > Studies have shown that people are less
likely to remember the brand name of a product in an ad with sex
and violence than in an ad without (BUSHMAN & BONACCI, 2002).
<end> (tons of text here)
Could it be something in the way my text is formatter that doesnt allow the replaceAll to work??
UPDATE:
Its definetly the end line characters
I removed them and it works. But i would still like to keep my end line characters is there any way i can do that ??
Output: