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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:49:15+00:00 2026-06-13T21:49:15+00:00

I’ve got a task in which I should capture specified text which cannot be

  • 0

I’ve got a task in which I should capture specified text which cannot be between headline (of any size) and anchor html tags (<h*></h*> and <a></a>) nor inside tag as attribute.

For example I’ve got text:

<h1>TfL</h1>
<a href="tfl.gov.uk">Tfl</a>
TfL is official organization for keeping London moving.

Is it possible to match “TfL” only outside those tags using regular expressions?

Many thanks.

Peter.

  • 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-13T21:49:17+00:00Added an answer on June 13, 2026 at 9:49 pm

    I ended up with selecting nodes using HtmlAgilityPack.HtmlDocument.SelectNodes() and then checking the node in selection if it is excluded tag or not and has or has not such parent (recursively).

    Public Const cAlphabet As String = "AÁÄBCČDĎEÉĚFGHIÍJKLĹĽMNŇOÓÔPQRŔŘSŠTŤUÚŮVWXYÝZŽ0123456789" ' Accepted chars '
    
    Dim nodes As HtmlNodeCollection = nothing
    Dim doc As HtmlDocument = New HtmlDocument()
    
    ' div encapsulation is used for text which is not between any tags. '
    ' iHtmlText is variable which holds html document in text form '
    doc.LoadHtml(String.Format("<div>{0}</div>", If(iHtmlText, String.Empty))) 
    
    ' "FIND_THIS_TEXT" can be any text which you want to find '
    ' Node selecting is case insensitive due to translate feature of xpath '
    nodes = doc.DocumentNode.SelectNodes(
            String.Format("//*[contains(translate(text(), '{0}', '{1}'), '{2}')]",
                          cAlphabet, cAlphabet.ToLower, "FIND_THIS_TEXT".ToLower))
    
    For Each node As HtmlNode In nodes
       If (IsNotOrNestedInSpecifiedNode(node, "a", "h1", "h2", "h3", "h4", "h5", "h6")) Then
           ' do something with the node here '
       End If
    Next
    

    IsNotOrNestedInSpecifiedNode function used in code above:

    Private Function IsNotOrNestedInSpecifiedNode(ByVal iNode As HtmlNode, ByVal ParamArray iExcludedHtmlTags() As String) As Boolean
            Dim ret As Boolean = False
    
            If (iNode.Name.IsIn(iExcludedHtmlTags)) Then
                ret = False
            ElseIf (iNode.ParentNode IsNot Nothing) Then
                ret = IsNotOrNestedInSpecifiedNode(iNode.ParentNode, iExcludedHtmlTags)
            Else
                ret = True
            End If
    
            Return ret
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.