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,'');
Comments
Post a Comment