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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:08+00:00 2026-05-23T09:00:08+00:00

I need to parse a html document that has been generated by saving a

  • 0

I need to parse a html document that has been generated by saving a word document as html.

I have been using the HTML agility pack quite successfully but in this instance I figured using regex for this one part might be easier (opinions?)

Word generates the following code when it translates one of its footnotes into html

<a href="#_ftn2" name="_ftnref2" title=""><span
class=MsoFootnoteReference><span class=MsoFootnoteReference><span
style='font-size:10.0pt'>[2]</span></span></span></a>

This output is consistent for every footnote with only the href= and name changing as well as the [2] text.

I need to extract the _ftn2 and [2] elements.

So far I have the following regex which will extract the _ftn2 part into the name group

<a href="#(?<name>_ftn\d).*>(<span class=MsoFootNoteReference>)

I’m having a bit of trouble parsing the second bit with all those span tags.

Is it going to be easier to use regex for this or should I continue to use the HAP for this part?

An an aside does anyone know why word generates nested identical span tags

<span class=MsoFootnoteReference>
  • 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-23T09:00:09+00:00Added an answer on May 23, 2026 at 9:00 am

    If the input follows exactly that format then you can get away with a pretty loose regex. You just need to ignore everything except the parts you want to extract and then employ non-greedy expressions to eat up all the garbage between them:

    <a href="#(?<name>_ftn\d).*?(?<number>\[\d+\]).*?<\/a>
    

    You can use a non-greedy .*? to eat up all the extra markup because nothing in there will match your next \[\d+\] pattern. You don’t really need the .*?<\/a> bit on the end, that’s mostly for symmetry and a bit of extra paranoia.

    Something like this is probably one of the few cases where using regular expressions to rip apart HTML makes sense. You could do this sort of thing with an HTML parser but then you’d be a nightmare of twisty XPath expressions (all of which look alike), DOM manipulations, or SAX events. And you might even get eaten by a grue.

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

Sidebar

Related Questions

We have a need to parse and extract the content from html files. We
I have an html-like xml, basically it is html. I need to get the
I have a swing client that renders HTML through the use of the JEditorPane
I need to parse an HTML file and i've got something like this: <TAG1>
So I need to pull some JavaScript out of a remote page that has
I am looking for a simple lightweight java library that parses HTML. I have
OK, I need to scan many HTML / XHTML documents to see if a
A recent blog entry by a Jeff Atwood says that you should never parse
I am testing against the following test document: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC
I have a project where I am taking some particularly ugly live HTML and

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.