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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:37:18+00:00 2026-06-05T15:37:18+00:00

haystack: <h2 >a&nbsp; &middot;&nbsp;&middot;&nbsp;&middot; </h2> <div class=indent> aaaa </div> <h2 >b&nbsp; &middot;&nbsp;&middot;&nbsp;&middot; </h2> <div

  • 0

haystack:

<h2 >a&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;
</h2>
<div class="indent">
aaaa
</div>
<h2 >b&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;
</h2>
<div class="indent">
bbbb
</div>

pattern I used:

#<h2[^>]*>(a|b)(?!</h2>)[\s\S]*</h2><div class="indent">((?!</div>)[\s\S]+)</div>#

this pattern only matches the first h2 content(e.g. a&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;) and the content in last div(e.g. bbbb)

but I whan it to match all content in the h2 and div to make an one to one map(e.g. a&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;=>aaaa,b&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;=>bbbb), how do I do this?

  • 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-05T15:37:20+00:00Added an answer on June 5, 2026 at 3:37 pm

    [\s\S]* and [\s\S]+ are greedy, meaning they will match as many characters as possible. Try changing them to [\s\S]*? and [\s\S]+?.

    With your current regex, if you were to put your [\s\S]* into a capturing group you would see that it matches the following:

    &nbsp; &middot;&nbsp;&middot;&nbsp;&middot;
    </h2>
    <div class="indent">
    aaaa
    </div>
    <h2 >b&nbsp; &middot;&nbsp;&middot;&nbsp;&middot;
    

    Adding the ? at the end makes this lazy, so instead of matching as much as possible it will match as few characters as possible, so it will stop at the first </h2> like you want. The same reasoning applies to the [\s\S]+ later in your regex.

    It also looks like this should fail on your sample string because you have </h2><div... in the middle of your regex, but in your sample text there is always a newline between the closing </h2> and the <div>, you should probably change this section to </h2>\s*<div.... End result:

    #<h2[^>]*>(a|b)(?!</h2>)[\s\S]*?</h2>\s*<div class="indent">((?!</div>)[\s\S]+?)</div>#
    

    But don’t parse HTML with regex!

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

Sidebar

Related Questions

Im using haystack to search my django website, it does this perfectly. However on
I am using django-haystack for search. By default it is showing oldest objects first
I have the following structure in a form: <div class='full'> <div class='half'> <label>Book</label> <select
This questions is about Django Haystack, with Whoosh backend. I would like to use
I'm implementing django-haystack for the first time and need to make a geo-spatial search.
I have this string: $string = 'foo bar php haystack needle' And i want
I have a problem with django-haystack. According to this tutorial I got this apps:
Main problem: ObjC can tell me there were six matches when my pattern is,
I'm trying to set up Haystack with Whoosh but am getting this value error
The haystack documentation (link below) makes this statement: Additionally, we're providing use_template=True on 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.