在javascript中使用regexp查找并删除字符串中的子字符串

在javascript中使用regexp查找并删除字符串中的子字符串,javascript,regex,Javascript,Regex,在Javascript或ruby中,我需要使用regex找到一个子字符串,并将其从可能包含多个子字符串的主字符串中删除 我的主弦是 My <style type="">first</style> name <style>is</style> xyz <style>abc</style>. 但是我找不到正确的方法。我得到的是 <style type="">first</style> name <

在Javascript或ruby中,我需要使用regex找到一个子字符串,并将其从可能包含多个子字符串的主字符串中删除

我的主弦是

 My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.
但是我找不到正确的方法。我得到的是

<style type="">first</style> name <style>is</style> xyz <style>abc</style>
名字是xyz abc
什么是正确的正则表达式

注意:不能使用任何JS库,如jquery和其他库。

这应该可以做到:

str = 'My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.';
str = str.replace("<style[^>]*?>.*?</style>","");
str='我的名字是xyz abc';
str=str.replace(“]*?>.*”,“”);
'我的名字是xyz abc。'

.replace(/]*>[^您还可以使用DOM解析来删除不需要的节点

var el = document.createElement('div');
el.innerHTML = 'My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.';
var styles = el.getElementsByTagName('style');
for(var i = styles.length - 1; i >= 0; i--){
    console.log(styles);
    el.removeChild(styles[i]);
}
el.innerHTML; // My name xyz
var el=document.createElement('div');
el.innerHTML='我的名字是xyz abc';
var styles=el.getElementsByTagName('style');
对于(var i=style.length-1;i>=0;i--){
console.log(样式);
el.removeChild(styles[i]);
}
el.innerHTML;//我的名字xyz
您可以试试这个

[]|[]|[]

[^]
更改为
[^
str = 'My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.';
str = str.replace("<style[^>]*?>.*?</style>","");
'My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.'
.replace(/<style[^>]*>[^<]*<\/style>/g,'');
"My  name  xyz ."
var el = document.createElement('div');
el.innerHTML = 'My <style type="">first</style> name <style>is</style> xyz <style>abc</style>.';
var styles = el.getElementsByTagName('style');
for(var i = styles.length - 1; i >= 0; i--){
    console.log(styles);
    el.removeChild(styles[i]);
}
el.innerHTML; // My name xyz