Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Regex Question

Regex Question

Scheduled Pinned Locked Moved Windows Forms
regexhtmltutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Burkhart
    wrote on last edited by
    #1

    I can usually muddle my way through creating a regular expression but this one has me stumped (even with Expresso). I need to search through the contents of a text box and find each word in an HTML doc, but avoid the text within the tags. I have a Regex that works fine in a plain text file, but not in a doc with tags. Example: <li>List Item</li> I'd want to find "List" and "Item" but not   "li" or "/li" If anyone has a Regex pattern that does this I'd love to see it, with thanks.

    R 1 Reply Last reply
    0
    • A Alan Burkhart

      I can usually muddle my way through creating a regular expression but this one has me stumped (even with Expresso). I need to search through the contents of a text box and find each word in an HTML doc, but avoid the text within the tags. I have a Regex that works fine in a plain text file, but not in a doc with tags. Example: <li>List Item</li> I'd want to find "List" and "Item" but not   "li" or "/li" If anyone has a Regex pattern that does this I'd love to see it, with thanks.

      R Offline
      R Offline
      Rob Smiley
      wrote on last edited by
      #2

      Alan, try this. The code originally came from the netSpell library, so i'm not 100% it works correctly... Private _htmlRegex As Regex = New Regex("</[c-g\d]+>|</[i-o\d]+>|</[a\d]+>|</[q-z\d]+>|<[cg]+[^>]*>|<[i-o]+[^>]*>|<[q-z]+[^>]*>|<[a]+[^>]*>|<(\[^\]*\|'[^']*'|[^'\>])*>", RegexOptions.IgnoreCase Or RegexOptions.Compiled)

      "An eye for an eye only ends up making the whole world blind"

      A 1 Reply Last reply
      0
      • R Rob Smiley

        Alan, try this. The code originally came from the netSpell library, so i'm not 100% it works correctly... Private _htmlRegex As Regex = New Regex("</[c-g\d]+>|</[i-o\d]+>|</[a\d]+>|</[q-z\d]+>|<[cg]+[^>]*>|<[i-o]+[^>]*>|<[q-z]+[^>]*>|<[a]+[^>]*>|<(\[^\]*\|'[^']*'|[^'\>])*>", RegexOptions.IgnoreCase Or RegexOptions.Compiled)

        "An eye for an eye only ends up making the whole world blind"

        A Offline
        A Offline
        Alan Burkhart
        wrote on last edited by
        #3

        Just ran it thru Expresso. It actually finds the tags, not the text between them. I have a Regex for stripping html, but I think this one might work better. So I can still use it. Thanks! Hadn't thought about it before but I've got a copy of NetSpell somewhere. I'll poke around inside and see what I can see. AB

        A 1 Reply Last reply
        0
        • A Alan Burkhart

          Just ran it thru Expresso. It actually finds the tags, not the text between them. I have a Regex for stripping html, but I think this one might work better. So I can still use it. Thanks! Hadn't thought about it before but I've got a copy of NetSpell somewhere. I'll poke around inside and see what I can see. AB

          A Offline
          A Offline
          Alan Burkhart
          wrote on last edited by
          #4

          Didn't find a Regex I could adapt in the NetSpell files. Will keep hammering on the thing. I keep thinking I'm missing something obvious but don't know yet what it is.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups