2017-05-29 90 views
-1

我有一個字符串tempType.tempcode中的數據,如下所示。在許多地方有網址的指向這樣的 -查找並替換爲角2

HREF = \ 「./資產/來源/模板/ .....」

我的要求是我想寫一功能,它將./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}}  \t </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> \t (function($){ \t \t $(window).load(function(){ \t \t \t $(".nav a").mPageScroll2id();             $("#lightSlider").lightSlider(); \t \t \t callCounter(); \t \t \t callvertical_list(); \t \t \t $(".menu2").sticky({ topSpacing: 0 }); \t \t }); \t })(jQuery); </script> </body> </html>

+0

這是什麼都與角呢?順便說一下,這真的很難正確格式化您的文章? – 2017-05-29 14:04:38

回答

0

對於每個變量,你必須使用像這樣一個正則表達式:

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

但是,如果它只在您的代碼中,只需在您的IDE中進行搜索並替換即可。 – trichetriche