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 105213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:24:13+00:00 2026-05-11T01:24:13+00:00

I am trying to match multiple CSS style code blocks in a HTML document.

  • 0

I am trying to match multiple CSS style code blocks in a HTML document. This code will match the first one but won’t match the second. What code would I need to match the second. Can I just get a list of the groups that are inside of my ‘style’ brackets? Should I call the ‘find’ method to get the next match?

Here is my regex pattern

^.*(<style type='text/css'>)(.*)(</style>).*$ 

Usage:

final Pattern pattern_css = Pattern.compile(css_pattern_buf.toString(),                      Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);   final Matcher match_css = pattern_css.matcher(text);         if (match_css.matches() && (match_css.groupCount() >= 3)) {             System.out.println('Woot ==>' + match_css.groupCount());             System.out.println(match_css.group(2));         } else {             System.out.println('No Match');         } 
  • 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. 2026-05-11T01:24:14+00:00Added an answer on May 11, 2026 at 1:24 am

    I am trying to match multiple CSS style code blocks in a HTML document.

    Standard Answer: don’t use regex to parse HTML. regex cannot parse HTML reliably, no matter how complicated and clever you make your expression. Unless you are absolutely sure the exact format of the target document is totally fixed, string or regex processing is insufficient and you must use an HTML parser.

    (<style type='text/css'>)(.*)(</style>) 

    That’s a greedy expression. The (.*) in the middle will match as much as it possibly can. If you have two style blocks:

    <style type='text/css'>1</style> <style type='text/css'>2</style> 

    then it will happily match ‘1</style> <style type=’text/css’>2’.

    Use (.*?) to get a non-greedy expression, which will allow the trailing (</style>) to match at the first opportunity.

    Should I call the ‘find’ method to get the next match?

    Yes, and you should have used it to get the first match too. The usual idiom is:

    while (matcher.find()) {     s= matcher.group(n); } 

    Note that standard string processing (indexOf, etc) may be a simpler approach for you than regex, since you’re only using completely fixed strings. However, the Standard Answer still applies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SRV.SYS is the SMB server driver. What the article is… May 11, 2026 at 8:03 pm
  • Editorial Team
    Editorial Team added an answer Thanks to Lewis comments I was able to reach this… May 11, 2026 at 8:03 pm
  • Editorial Team
    Editorial Team added an answer With the help of this link. I was able to… May 11, 2026 at 8:03 pm

Related Questions

I am essentially trying to create a version of the figure element (upcoming in
I am trying to parse url-encoded strings that are made up of key=value pairs
I've been working on getting this program complete where it saves multiple structs to
I have a webapp development problem that I've developed one solution for, but am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.