views:

412

answers:

2

Who can help me with regular expression , to remove some string with jquery, don't have much experience in regex

<div class="test" >
    &nbsp;&gt;&nbsp;&nbsp;&gt;&nbsp;Test Text
</div>

I want to remove "&nbsp;&gt;&nbsp;&nbsp;&gt;&nbsp;" and to leave just the text

Thanks!!

+2  A: 

Like this:

$('.test').html(function(i, old) { return old.replace(/&(nbsp|gt);/g, ''); });

EDIT: Demo

SLaks
it removes all text
Alexander Corotchi
+1  A: 
$('.test').html($('.test').html().replace(/&[^;]+;/g, ''))
theraccoonbear
it is adding \n\n\n at the end
Alexander Corotchi
I answered this in your previous question. `.text().replace(/(^\s+|\s+$|(.*)>\s*)/g,"")`
ghoppe
Color me skeptical, but is the code you're testing against identical to what you have in your question? This code can't even introduce new characters, it only replaces matches with empty strings.
theraccoonbear
if @ghoppe is right, it sounds like you *already* had the line breaks there.
theraccoonbear
@theraccoonbear The line breaks follow the text before the ending `</div>` tag. Your regex doesn't take that into account. So Alex used poor phrasing. It's not adding anything. It's just not removing what he wants removed. :)
ghoppe
thanks man !!!!!! You are right ..
Alexander Corotchi