查找并替换角度2

时间:2017-05-29 13:29:57

标签: javascript angular

我在字符串tempType.tempcode中有一个数据,如下所示。在很多地方都有这样的网址 -

  

HREF = \" ./资产/来源/模板/.....&# 34;

我的要求我想写一个功能,将所有./assets/sources/template替换为sources/template。请指导



    tempType.tempcode = < !DOCTYPE html > < html lang = "en" > < head > < meta charset = "utf-8" > < meta http - equiv = "X-UA-Compatible"
    content = "IE=edge" > < meta name = "viewport"
    content = "width=device-width, initial-scale=1" > < meta name = "description"
    content = "" > < meta name = "author"
    content = "" > {
        {
            META
        }
    } < link rel = "stylesheet"
    href = "./assets/sources/template/css/bootstrap.min.css"
    type = "text/css" > < link href = "https://fonts.googleapis.com/css?family=Poppins"
    rel = "stylesheet" > < link href = 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800'
    rel = 'stylesheet'
    type = 'text/css' > < link href = 'http://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic'
    rel = 'stylesheet'
    type = 'text/css' > < link rel = "stylesheet"
    href = "./assets/sources/template/font-awesome/css/font-awesome.min.css"
    type = "text/css" > < link rel = "stylesheet"
    href = "./assets/sources/template/css/animate.min.css"
    type = "text/css" > < link rel = "stylesheet"
    href = "./assets/sources/template/css/light-slider.css"
    type = "text/css" > < link rel = "stylesheet"
    href = "./assets/sources/template/css/style.css"
    type = "text/css" > < link rel = "stylesheet"
    href = "./assets/sources/template/css/common.css"
    type = "text/css" > < /head>  <body id="page-top">      <div id="main-wrapper">           {{CONTENT}}    	  </div > <!-- jQuery -->     <script src="./assets/sources/template/js/jquery.js"></script>      <!-- Bootstrap Core JavaScript -->     <script src="./assets/sources/template/js/bootstrap.min.js"></script>      <!-- Plugin JavaScript -->     <script src="./assets/sources/template/js/jquery.easing.min.js"></script>     <script src="./assets/sources/template/js/jquery.fittext.js"></script>     <script src="./assets/sources/template/js/wow.min.js"></script>  <script src="./assets/sources/template/js/popupimage.js"></script>     <!-- Custom Theme JavaScript -->    <script src="./assets/sources/template/js/creative.js"></script>  <script src="./assets/sources/template/js/light-slider.js"></script> <script src="./assets/sources/template/js/count.js"></script> <script src="./assets/sources/template/js/menu.js"></script>  <script src="./assets/sources/template/js/vertical_list.js"></script> <script src="./assets/sources/template/js/sticky.js"></script> <script src="http://www.jqueryscript.net/demo/jQuery-Plugin-For-One-Page-Navigation-Plugin-Page-Scroll-To-ID/jquery.malihu.PageScroll2id.js"></script> <script> 	(function($){ 		$(window).load(function(){ 			$(".nav a").mPageScroll2id();                                                 $("#lightSlider").lightSlider(); 			 callCounter(); 			 callvertical_list(); 			  $(".menu2").sticky({ topSpacing: 0 }); 		}); 	})(jQuery); </script> </body>  </html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

对于每个变量,您必须使用如下所示的Regexp:

let pattern = '(./assets/sources/template)';
let regex = new RegExp(pattern, 'g');
let newString = yourVariable.replace(regex, 'sources/template');