Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts

    Erasing html tags

    If I am given any link such as:

    <a href="http://blah">I want this text</a>

    How do I chop off the html tags so I get just "I want this text"?

    Is regular expressions the only way to accomplish this?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    London
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep - I tend to do this in javascript - have a whole host of functions like that...

    Try this...

    var sHTML = variableName;
    sHTML = sHTML.replace(/<[^>]*>/g, "");
    return sHTML;

    So if you're pulling stuff from a form just call the function on submit and use the form reference instead of variable name.

    If you want to do it using ASP/VBScript, go to this article of 4guys... tells you everything you need to know.

    http://www.4guysfromrolla.com/webtech/073000-1.shtml

    dominicall
    Last edited by dominicall; 02-26-2003 at 10:09 AM.
    dominicall - confusing himself more and more each day

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any regex that works in javascript should work pretty much exactly the same in VBScript, or C# in .NET with little or no modification.

    Sorry I didn't elaborate more, with your experience I figured you could find plenty of examples, such as the one dominicall posted.

    Strangely enough, I was working with another developer today parsing out https?\/\/\s?=\s?["']([^"'\s]*) links (something like that).
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •