Results 1 to 2 of 2

Thread: JavaScript Replace

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    JavaScript Replace

    I have the following code:
    text = text.replace(/<[^>]*>/gi,'');

    Which I believe should strip any HTML formatting from a string. Can any one adapt this to strip everything but line breaks (<br>).

    Help appreciated.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  2. #2
    Member
    Join Date
    Oct 2005
    Posts
    35

    Re: JavaScript Replace

    You don't really need to adapt it, just alter your <br> before using that line, and then change your <br> back. Here is how I would go about it.

    1. Change every <br> to |br|(or something similiar to |br|)
    2. Use: text = text.replace(/<[^>]*>/gi,'');
    3. Change all |br| back to <br>

    Then you would have removed all the syntax except for all of the <br>

Posting Permissions

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



Click Here to Expand Forum to Full Width