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

The Archive Base Latest Questions

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

I have data in the form: <ol> <li>example1</li> <li>example2</li> <li>example3</li> </ol> which needs to

  • 0

I have data in the form:

<ol>
<li>example1</li>
<li>example2</li>
<li>example3</li>
</ol>

which needs to turn into

# example1
# example2
# example3

The pound sign has to be associated with the ol html tag. I’m using java regular expressions and this is what I have so far:

info = info.replaceAll("(?s).<ol>\n(<li>(.*?)</li>\n)*</ol>","# $2");

info is a string object containing the data. Also there may be line breaks in between the li tags.When I run it, it only prints the last item. i.e the result is

 # example3

example2 and example1 are missing

Any thoughts on what I’m doing wrong?

  • 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-23T16:20:41+00:00Added an answer on May 23, 2026 at 4:20 pm

    Your regex has a couple of problems:

    • it contains a capturing group inside a capturing group
    • overall, it will only match once (it includes for a start — there’s only one of these.

    The solution I’d recommend: don’t tie yourself in knots. Write a loop with a Matcher.find(), pulling out the matches one by one and adding them to a string buffer. It would go something like this:

        Pattern p = Pattern.compile("<ol>(.*?)</ol>");
        Matcher m = p.matcher("...");
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            sb.append("#").append(m.group(1)).append("\n");
        }
        String result = sb.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code I use to insert form data into a single
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have following Situation, Server A sends some data (HTML form) to server B,
i have a submit page in html . when i submit the form data,
I have a couple of controllers on my site which are handling form data.
I have a MySQL insert query which needs to pull one data field from
I have a JavaScript-based timeline which needs to use data from an SQL server.
If I have a data capture form with either tapstrips and or two columns
I have some data in this form (dictionary): Value0 Text1 Value1 Text2 Value2 Text3
I have created application where i just need to access data form assets folder.

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.