Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:41:05+00:00 2026-06-04T04:41:05+00:00

I would like to remove all substrings from a string in java that begin

  • 0

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 ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:41:06+00:00Added an answer on June 4, 2026 at 4:41 am
    String s = "text that needs WHAT DO YOU WANT TO KNOW ? " +
            "more text that needs deletion <end>to stay";
    System.out.println(s.replaceAll("(?s)WHAT DO YOU WANT TO KNOW \\?.*?<end>", ""));
    

    Output:

    text that needs to stay
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to remove a trailing slash from a string. For example if
I would like to remove/uninstall directX End-User that I downloaded and installed it from
How would you remove a specific string from a text file (command line) e.g.
I have a string that i would like to remove all occurrences of <br>
I would like to remove all occurrences of a given value from within a
I would like to trim all special characters from a string in SQL. I've
I would like to remove all HTML comments from my facelets before delivering to
I would like to remove all elements from XML except content of element called
I would like to remove any ABC at the end of the string. The
I would like to remove any ABC at the end of the string. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.