JavaScript正则表达式
我想删除标签,并使标签之间的选定文字上方,不知道如何JavaScript正则表达式,javascript,regex,Javascript,Regex,我想删除标签,并使标签之间的选定文字上方,不知道如何 var pattern = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.' var myRegexp = /<upcase>(.*?)<\/upcase>/g; var match = "$1"; var str = pattern.replace(myRege
var pattern = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.'
var myRegexp = /<upcase>(.*?)<\/upcase>/g;
var match = "$1";
var str = pattern.replace(myRegexp, match.toUpperCase());
console.log(str);
var pattern='我们住在一艘黄色的潜艇上。'
var myRegexp=/(.*)/g;
var match=“$1”;
var str=pattern.replace(myRegexp,match.toUpperCase());
console.log(str);
您需要使用回调函数来替换,以便将匹配的值提供给它并进行处理
var str = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.'
var str = str.replace(/<upcase>(.*?)<\/upcase>/g, function($0) { return $0.toUpperCase(); });
alert(str);
var str='我们住在一艘黄色的潜艇上。'
var str=str.replace(/(.*)/g,函数($0){return$0.toUpperCase();});
警报(str);
至于移除标签:
str = str.replace(/<\/?[^>]+>/g, '');
str=str.replace(/]+>/g',);
.您需要使用回调函数替换,以便将匹配的值提供给它并进行处理
var str = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.'
var str = str.replace(/<upcase>(.*?)<\/upcase>/g, function($0) { return $0.toUpperCase(); });
alert(str);
var str='我们住在一艘黄色的潜艇上。'
var str=str.replace(/(.*)/g,函数($0){return$0.toUpperCase();});
警报(str);
至于移除标签:
str = str.replace(/<\/?[^>]+>/g, '');
str=str.replace(/]+>/g',);
.您需要一个XML/HTML解析器您的目标是什么?您正在制作一些新的标记语言吗?请尝试
var str=pattern.replace(myRegexp,(m,m1)=>m1.toUpperCase())代码>m1
对应于(.*)
第一个捕获组。您需要一个XML/HTML解析器您的目标是什么?您正在制作一些新的标记语言吗?请尝试var str=pattern.replace(myRegexp,(m,m1)=>m1.toUpperCase())代码>m1
对应于(.*)
第一捕获组。您的问题保持不变,我已经回答了。您的问题保持不变,我已经回答了。