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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:09:36+00:00 2026-06-06T13:09:36+00:00

I have a content string that starts with an unordered list I want to

  • 0

I have a content string that starts with an unordered list I want to make a summary of this content on my homepage and I need to match the first unordered list and only show 5 list items in the preview, so I stated with matching the whole ul tag using this regex:

/<\s*ul[^>]*>(.*?)<\s*/\s*ul>/s

it works fine in regex tester online but I get Unknown modifier ‘\’ and I don’t know which one ? also after getting the whole unordered list how can I choose only the first 5 list items for example:

<ul class="mylist">
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
    <li>Lorem Ipsum Dolor Sit Amet</li>
</ul>

and I want to create the same one with only the first 5 <li> tags, so should I use regex or some other methods in php ?

and thanks in advance.

  • 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-06T13:09:38+00:00Added an answer on June 6, 2026 at 1:09 pm
    /<\s*ul[^>]*>(.*?)<\s*/\s*ul>/s
    

    you need to escape the / if you use it as the delimiter.

    /<\s*ul[^>]*>(.*?)<\s*\/\s*ul>/s
    

    in PHP you can use any character as the delimiter, though:

    #<\s*ul[^>]*>(.*?)<\s*/\s*ul>#s
    

    You can repeat a pattern:

    #<\s*ul[^>]*>(\s*<li>.+?</li>){5}#sm
    

    will match 5 <li>s. You won’t be able to access them seperately, though. You can either unroll that repeated-group, or run a second expression to extract the <li>s.

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

Sidebar

Related Questions

I have a String with this content: href=http://www.website.com/ /> [...] [...] I just want
currently, this is the preg_replace string that I have. $mtg_post['post_content'] = preg_replace([^\\x20-\\x7e], ,$ability); This
I have an Activity that starts a Service. In my Activity: startService(new Intent(this, MyService.class));
What I want is that when Activity starts first time, it first checks if
I have this in my OnItemClick method. final String[] links = getResources().getStringArray(R.array.pokemon_stats); String content
I have a file with chinese content that I need to parse. Each post
I have a string which has the below content String msg = The variables
I have an example json as below: { Passwd:String content, Userme:String content } how
I have the following class: private class NodeTemp { public string Content; public NodeTemp
I have this ImageView in my layout: <ImageView android:layout_width=fill_parent android:layout_height=wrap_content android:contentDescription=@string/image_divider android:paddingBottom=8dp android:paddingTop=4dp android:scaleType=fitXY

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.