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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:38:00+00:00 2026-06-12T23:38:00+00:00

I’m using a 3rd party app that uses regex to searches html documents, in

  • 0

I’m using a 3rd party app that uses regex to searches html documents, in this case it doesn’t have proper structure (no head or body), and returns the matches as a form of properties in an excel file. It does not parse them. I already know the horrors induced by attempting to parse html with regex.

So I wrote a regex that is supposed to capture every sentence within a paragraph or list item but after checking the matches I noticed that sometimes it wouldn’t match all the sentences and would stop matching once that sentence or list item gave an error. Almost always with the list item but occasionally with sentences. After realizing this was due to human error, I added the optional non-capture group that totally screwed everything up.

This was the initial regex I wrote which worked in most cases:

([^<>]*?)[.!?<]|[ <"'/]

Because of some sentences having an error where the writer put a space before the punctuation, I added the optional non-capture group:

([^<>]*?)(?:[ ])?[.!?<]|[ <"/l]

Here is an example of the text it was searching:

Buy this because it is soooooooooooooooooooo freaking awesome! If you buy this 
everyone will think you're "cool." You'll get all the babes !<br><br><ul><li>It 
will make you smell better<li>It will make you preform better.</li><li>Will make
you last longer in bed!<li>Will fix any acne problem.</li> <li>It will reduce the
amount you perspire to .01% your normal amount!<br><li>It will make you 
"invincible."</li></ul>

Because their is nothing to use as an anchor (text starts at beginning of the html file) I just had it start capturing immediately. As you see, it is poorly coded and has grammar errors, which is why I ended it the way I did.

The first one captured most all the sentences but left out some… The second one returns a bunch of blank of null match which screw up the arrays made with the captures. It’s like its disregarding everything after the non-capture group.

I thought about doing it this way but this returned every single word as a match:

([^<>]*?)[ .!?<]|[ .!?<"/l]

Only problem was this cut some sentences off in the middle and would require a third range which I think would have a bunch of different options (notice the random <br> tag) and would take a while to find them all.

From appearances, it is not using the optional non-capture group! Why is this? Or am I overlooking something extremely simple? I feel like the latter is probably the case.

  • 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-12T23:38:01+00:00Added an answer on June 12, 2026 at 11:38 pm

    I came up with this beast:

    (?:^|\s+|>)((?:[^<>.!?\s])(?:[^<>.!?]|\.\d)+(?:\.(?!\d)"?|!|\?)?)
    

    Let me try to explain what I am doing here.

    (?:^|\s+|>)       # only start after at the string's beginning, after a row of
                      # spaces, or after closing a tag
                      # this eliminates all in-tag matches (like "li" and "br")
    (                 # opening a capturing group that will contain the actual match
    (?:[^<>.!?\s])    # require at least one character that is not in the given group
                      # this eliminates matching a single space between two <li>s
                      # NOTE: there are probably better ways to do this
    (?:[^<>.!?]|\.\d) # defines possible sentence characters; allow everything but
                      # <, >, ., !, ? EXCEPT FOR . followed by a digit
    (?:\.(?!\d)"?|!|\?)?
                      # include possible sentence endings; that is . not followed by
                      # a digit (hence, the negative lookahead), but possibly
                      # followed by ", or !, or ?, or nothing at all
    )                 # close the main matching group
    

    Now you should be able to access your sentences at captured index 1.

    I believe you might have cases where my assumptions about what a sentence can look like break. But I could only work from the example you have given, and all its oddities are included.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.