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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:48+00:00 2026-05-23T03:26:48+00:00

I want to find a match in a html string. That will not be

  • 0

I want to find a match in a html string.

That will not be between html tags or inside them.

For example:

the word is : ue

<span color=blue>ue</span>ue<span>sdfsd</span>

so I want to find only the third match (not inside “blue”) and not between the span tags.

Thanks

  • 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-23T03:26:49+00:00Added an answer on May 23, 2026 at 3:26 am

    You’re trying to use regular expressions to parse HTML. HTML cannot be readily, reliably processed with a regular expression on its own.

    If you’re doing this on a browser, you can instead leverage the browser’s highly-optimized HTML parser.

    If you want to detect the word when there’s a tag in-between (e.g., “u<hr>e”):

    var element, node, topLevelText;
    element = document.createElement('div');
    element.innerHTML = "<span color=blue>ue</span>ue<span>sdfsd</span>";
    topLevelText = "";
    for (node = element.firstChild; node; node = node.nextSibling) {
        if (node.nodeType === 3) { // 3 = text node
            topLevelText += node.nodeValue;
        }
    }
    if (topLevelText.indexOf(word) >= 0) {
        // Found
    }
    

    If you only want to detect it between things (so, your example but not “u<hr>e”):

    var element, node;
    element = document.createElement('div');
    element.innerHTML = "<span color=blue>ue</span>ue<span>sdfsd</span>";
    for (node = element.firstChild; node; node = node.nextSibling) {
        if (node.nodeType === 3) { // 3 = text node
            if (node.nodeValue.indexOf(word) >= 0) {
                // Found
            }
        }
    }
    

    (Both of those do case-sensitive matching.)

    That does this

    1. Creates an element that isn’t displayed anywhere using document.createElement.
    2. Parses the HTML text by assigning it to innerHTML on the element. This property has only recently been standardized, but it’s been supported by all major browsers for a decade or so.
    3. Looks through the immediate children of the node, which will include any elements created by parsing, and text nodes for the top-level text in the string (e.g., text in the place where you want to search for it). This is using Node#firstChild, Node#nodeType, Node#nodeValue, and Node#nextSibling.
    4. Depending on whether you want to find it in the “u<hr>e” situation, it either looks directly at the text in each of the text nodes, or it builds them all up into a string and searches that afterward.

    The links above are mostly to the DOM2 Core spec, most of which is supported by most browsers. Other references that can be handy:

    • DOM2 HTML specification (HTML-specific DOM stuff)
    • DOM3 Core Spec (newer DOM stuff)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find and match strings that contain no HTML tags but <br/>
I am trying to find HTML tags, via PHP ereg, that has a {xxx}
I want to find any text in a file that matches a regexp of
I want to find a sql command or something that can do this where
I want to find an SQL query to find rows where field1 does not
I want to find a linux command that can return a part of the
I want to parse an HTML document and extract a certain div block that
Im trying to do a regex where I can find all html tags, but
I want to use a temp directory that will be unique to this build.
I have a string containing html and tags in the form [realtor:name] or [office:phone].

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.