0

I got emails and trying to display them on the page in a div. But the mail I got contains body css like body{background-color: #444} makes my pages looked wierd. I am trying to remove the body rule from css. I use jsoup got the style tag html, the only question is how can I remove the rule by regex?

1 Answer 1

3

Try this:

String withoutBody = text.replaceAll("body\\s*\\{.*?\\}", "");

Notes;

  • you must escape the {} chars
  • in java you must escape the backslash too, that's why they are doubled
  • the ? in .*? makes the match non-greedy, which means it won't match with another } after the body CSS tag
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.