Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16343

Re: str.replace() not catching, need a second set of eyes

Newsgroups comp.lang.javascript
Subject Re: str.replace() not catching, need a second set of eyes
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <8815d054-214a-4c1d-b8d4-19c0916589e3@googlegroups.com>
Message-ID <XnsA0E1AB80D3AD7eejj99@194.109.133.133> (permalink)
Date 2012-10-03 14:51 +0000

Show all headers | View raw


Jason C wrote on 03 okt 2012 in comp.lang.javascript:

> I'm working with a contenteditable field. When someone pastes data
> that includes <span... itxt...>...</span> or <a
> href...rel="nofollow"...>...</a>, I want the tags to be removed. 
> 
> Here is the exact code I'm using:
> 
> a = a.replace(/<span [^>]*?itxt[^>]*?>([\s\S]*?)<\/span>/gi, '$1');
> a = a.replace(/<a
> href=[^>]*?rel=["']nofollow[^>]*?>([\s\S]*?)<\/a>/gi, '$1'); 
> 
> 
> This works 99.9% of the time, but every once in awhile, I'll have
> something like this come through: 
> 
> <a href="http://www.example.com/?start=0&amp;h=20121001202337#"
> rel="nofollow" id="itxthook1" class="itxtnewhook>whatever</span></a> 
> 
> 
> Specifically, notice that the class="itxtnewhook doesn't have a
> closing ", and there's a closing </span> without an opening <span>. 
> 
> Since this is being modified onPaste, I don't see the text before it's
> submitted, and I haven't been able to duplicate it myself so I'm
> guessing that it's related to a specific browser. But can you guys see
> what I'm missing in my str.replace() script that's letting this slip
> through? 

Some ancient browsers, including IE7,
do not have nongreedy regex parsing.


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

str.replace() not catching, need a second set of eyes Jason C <jwcarlton@gmail.com> - 2012-10-03 02:25 -0700
  Re: str.replace() not catching, need a second set of eyes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 14:51 +0000
    Re: str.replace() not catching, need a second set of eyes Jason C <jwcarlton@gmail.com> - 2012-10-03 12:36 -0700
      Re: str.replace() not catching, need a second set of eyes Danny <dann90038@gmail.com> - 2012-10-03 13:36 -0700
      Re: str.replace() not catching, need a second set of eyes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-04 07:47 +0000
        Re: str.replace() not catching, need a second set of eyes Jason C <jwcarlton@gmail.com> - 2012-10-05 01:42 -0700
          Re: str.replace() not catching, need a second set of eyes Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-06 19:10 +0100

csiph-web