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 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    67
    Thanks
    19
    Thanked 0 Times in 0 Posts

    How to match in replace() resp. regex all whitespaces INCLUDING   and &tab;?

    Assume I have a web page whose original html source contains

    ...<p>&nbsp;</p>...

    Now I want to replace this pattern after loading and before displaying with the following (simpliyifed) command:


    document.body.innerHTML=document.body.innerHTML.replace(/<p>\s*<\/p>/g,"dummy");


    Unfortunately this does not work because \s does NOT include &nbsp; (or &tab;)

    How can I extend the command above to include &nbsp; and &tab; as well?

    Peter
    Last edited by pstein; 08-01-2014 at 12:26 PM.

  2. #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,493
    Thanks
    57
    Thanked 636 Times in 631 Posts
    wouldn't that be
    Code:
    document.body.innerHTML=document.body.innerHTML.replace(/<p>(\s*|&nbsp;|&tab;)<\/p>/g,"dummy");


 

Posting Permissions

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