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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Regular Expression for link in vb.net label.

Regular Expression for link in vb.net label.

Scheduled Pinned Locked Moved ASP.NET
regexcsharpdatabasehelp
3 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.
  • U Offline
    U Offline
    User 4122428
    wrote on last edited by
    #1

    Hi All, I've got text going into a DB which may contain links, or naked URL's. I do cleanup on the way in to avoid XSS attacks, but on the way out, I want any URL's to display as links. So, I've got a couple possibilities. If the link is already within an anchor tag, then I want it to display properly as a link. If the link is a plain URL within the text, I need to add an anchor tag. I'm currently using: Regex.Replace(dr.Item(1), "(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", Function(match As Match) String.Format("<a href=""{0}"">{0}</a>", match.ToString()), RegexOptions.IgnoreCase) This will add an anchor tag surrounding a naked URL, but what I need is for it not to act on a URL that is already within an anchor tags. Help please?

    N U 2 Replies Last reply
    0
    • U User 4122428

      Hi All, I've got text going into a DB which may contain links, or naked URL's. I do cleanup on the way in to avoid XSS attacks, but on the way out, I want any URL's to display as links. So, I've got a couple possibilities. If the link is already within an anchor tag, then I want it to display properly as a link. If the link is a plain URL within the text, I need to add an anchor tag. I'm currently using: Regex.Replace(dr.Item(1), "(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", Function(match As Match) String.Format("<a href=""{0}"">{0}</a>", match.ToString()), RegexOptions.IgnoreCase) This will add an anchor tag surrounding a naked URL, but what I need is for it not to act on a URL that is already within an anchor tags. Help please?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Save yourself the trouble and clean the anchor tags from the string prior to saving to the database. As a rule of thumb you should never store formatted items in the database, let the formatting happen at the presentation layer. That way when the business rules change, or the data needs to be used in different context, it's easier to adapt.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • U User 4122428

        Hi All, I've got text going into a DB which may contain links, or naked URL's. I do cleanup on the way in to avoid XSS attacks, but on the way out, I want any URL's to display as links. So, I've got a couple possibilities. If the link is already within an anchor tag, then I want it to display properly as a link. If the link is a plain URL within the text, I need to add an anchor tag. I'm currently using: Regex.Replace(dr.Item(1), "(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", Function(match As Match) String.Format("<a href=""{0}"">{0}</a>", match.ToString()), RegexOptions.IgnoreCase) This will add an anchor tag surrounding a naked URL, but what I need is for it not to act on a URL that is already within an anchor tags. Help please?

        U Offline
        U Offline
        User 4122428
        wrote on last edited by
        #3

        Ok, I've narrowed down the question. I have a Regex that matches a naked URL ( http://www.whatever.com/whatever.... ) What I need to know is what to add to the beginning and end of that Regex so that it does not match if there is a double quote right before or after the URL. It's the "NOT QUOTES" thing that I'm not getting.

        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