javascript - Regex replacing more than I want -


i want delete body element 1 class starts demo-xxx xxx can character , without fix length.

so can have in body

<body classs="bye demo-hello water"> 

i using regex /\b\s?demo-.*\b/g so:

$("body")[0].classname = $("body")[0].classname.replace(/\b\s?demo-.*\b/g, ''); 

but removing classes after demo-xxx, such water:

<body classs="bye"> 

you need exclude space usintg ^\s , 1 or more characters use + instead of *

$("body")[0].classname =$("body")[0].classname.replace(/\b\s?demo-[^\s]+\b/g,''); 

demo


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -