2017-07-16 44 views
0

正確的字符串我有一個字符串以下假設值:打通正則表達式

//start string: 
var text1 = 'Me & You'; 
var text2 = 'Me& You'; 
var text3 = 'Me &You'; 
var text4 = 'Me&You'; 
var text5 = 'Me  &You'; 
var text6 = 'Me&  You'; 
var text7 = 'Me  & You'; 
//Final string I want to get: 
text1: Me You 
text2: Me You 
text3: Me You 
text4: MeYou 
text5: Me  You 
text6: Me  You 
text7: Me  You 
//real output: 
text1: Me You 
text2: Me You 
text3: Me &You 
text4: MeYou 
text5: Me  //Here are many hidden spaces 
//and similar outputs 
//hypothetical RegExp 
var string = 'Me  & You'; 
let value = /\S*(&|#|%)\S*/;//for example 
let resssC = string.split(value)... 

我怎樣才能得到所需要的輸出?這是一個正則表達式的問題還是還有其他什麼?

回答

1

,因爲我以爲你只更換&

string.replace(/\&/g,""); 
0

也許就是這麼簡單:?

console.log(string.split("&").join(""))