0

I have a string in Java not escaped which contains CSS, JavaScript and HTML.

I need to extract all the CSS from this string, so basically I need to search for everything that start for <style and finish for </style> and everything that start for <link and finish for >

Any suggestions?

4
  • So basically you need a HTML parser. Commented May 3, 2013 at 1:42
  • I need to retrieve all the CSS because I want inject it in the HEAD tag instead the BODY Commented May 3, 2013 at 1:44
  • 1
    Yeah like Qtax said, a HTML parser could help you easily find the CSS. A Java HTML parser I've used before which uses jQuery like selectors, which I find convenient, can be found here: jsoup.org Commented May 3, 2013 at 1:45
  • Do you need to do this in JavaScript or Java? Commented May 3, 2013 at 1:47

1 Answer 1

2

The regex might look something like this. String result = searchText.replaceAll("<style>([^<]*)</style>", "$1"); this should change the text to whats inside the tag, just modify it slightly for the 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.