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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:05:23+00:00 2026-05-20T01:05:23+00:00

I have the following input <div style=s1>title1</div> <div style=s1>content1</div> <div style=s1>title2</div> <div style=s1>content2</div> I

  • 0

I have the following input

<div style="s1">title1</div>
<div style="s1">content1</div>
<div style="s1">title2</div>
<div style="s1">content2</div>

I know title1 and title2 and I want to collect content1 and content2

I would need something like this:

<div style="s1">title1</div>.*?<div style="s1">(.*?)</div>

but since regexp is greedy, it matches until the end so it returns

content1</div>
    <div style="s1">title2</div>
    <div style="s1">content2

I would like to add to the pattern a list of tags that should not be included in the match.

Something like:

<div style="s1">title1</div>.*?<div style="s1">(.*?[^<div])</div>

where I refer with [^<div] to a not contain stuff. This should be multiple options, probably with the use of |

How can I do it?

  • 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-05-20T01:05:24+00:00Added an answer on May 20, 2026 at 1:05 am

    Obligitory link.

    Now that that is out of the way, just do some dom manipulation and xpath:

        $dom = new DOMDocument();
        @$dom->loadHTML($html);
        $x = new DOMXPath($dom);        
    
        foreach($x->query("//div") as $node)
        {
           if (trim($node->textContent) == 'title1')
           {
               $content['title1'] = $node->nextSibling->textContent;
           }
        }
    

    Now wasn’t that easy? So no more regexing html kay?

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

Sidebar

Related Questions

I have something like the following <div id=container> <ul id=name_list> <li class=name> <input type=hidden
I have the following: <div style=float: left; padding-right: 1%;> <label class=editor-label for=BrowserTitle>Browser Title</label> <input
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have the following code: HTML <div id='foo'> <input type='checkbox' value='english' name='bar[english]' /> <input
I have the following code: ​<div id=container> <input type=text name=a1 id=a1> <input type=text name=a2
for example I have the following: <div class=both> <textarea data-id=1 name=t1>Value 1</textarea> <input type=checkbox
i have the following problem with that code in my html tag: <div id=searchbar><input
I have some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode
Assume I have the following input in Pig: some And I would like to
I have the following markup: <div style=width: 660px; border-bottom: 1px solid #3A3F46;> <div class=noplace_event_cont>

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.