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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:07:49+00:00 2026-06-03T04:07:49+00:00

Using php and Regex I am attempting to add <li>Valid in US</li> in the

  • 0

Using php and Regex I am attempting to add <li>Valid in US</li> in the last UL after the last LI or to simply put after the last LI.

When debugging I cannot even get the contents of the last UL tag. This code brings up nothing when I do a var_dump (I have also tried preg_match_all with it):

if (preg_match("/((<ul>(.*?)<\/ul>/s){3})", $desc, $WARRANTY) == true)
var_dump($WARRANTY);

This is contents of $desc:

<h1>Stuff</h1>
<p>description</p>
<hr />
<strong>Features &amp; Benefits</strong>
<ul>
  <li>feat</li>
  <li>feat</li>
  <li>feat</li>
</ul>
<hr />
<strong>Specifications</strong>
<ul>
  <li>spec</li>
  <li>spec</li>
  <li>spec</li>
</ul>
<hr />
<strong>Warranty Information for a certain product</strong>
<ul>
  <li>3 Years Parts</li>
  <li>3 Years Labor</li>
</ul>
<div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
  • 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-03T04:07:50+00:00Added an answer on June 3, 2026 at 4:07 am

    If you want to match the <ul> tag with only 2 <li> tags in it, you can use this regex:

    <ul>\s*(<li>[^<]+</li>\s*){2}</ul>
    

    I can suggest another hacky way of adding the third li tag:

    • use this regex:

      <ul>\s*(?:<li>[^<]+</li>\s*){2}(<)/ul>

    • and replace the match in the first group with your <li></li> content followed by a < – because that’s what has been captured by the group (<)

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

Sidebar

Related Questions

I'm using PHP. I'm trying to get a Regex pattern to match everything between
I want to differentiate between the following 2 html tags using php + regex
Assuming the input string +123-321+123 345 , using PHP's regex functions I would like
I'm trying to parse a php code using some regex and I'm stuck at
Im parsing the source of a website and Im using this regex: /page\.php\?id\=([0-9]*)\\>(.*)\<\/a\>\<\/span\>/.match(self.agent.page.content) self.agent.page.content
Using Php is it possible to detect exact OS even if the browser agent
Possible Duplicates: How do I extract HTML content using Regex in PHP RegEx match
I want to copy a substring of a string using PHP. The regex for
I've been using the following site to test a PHP regex so I don't
I'm using PHP's preg_match_all() to search a string imported using file_get_contents(). The regex returns

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.