2017-02-16 118 views
0

這是我有文字:正則表達式來刪除 「= R」

[ ' 
    "message": "WorldStage Supports Massive 4K Video Mapping at Adobe MAX=\r 
with Christie Boxer 4K Projectors', 
    ' 
    "message": "Inside Track: Trading Focus on Shares of Adobe Systems In=\r 
c. (ADBE)' ] 

我希望它看起來像:

[ ' 
    "message": "WorldStage Supports Massive 4K Video Mapping at Adobe with Christie Boxer 4K Projectors', 
    ' 
    "message": "Inside Track: Trading Focus on Shares of Adobe Systems Inc. (ADBE)' ] 

正則表達式我想:

texts[i].replace(/=\\r/g, "") 

但它不工作。可以在StackOverflow中找到類似的問題。 :(

+1

它是一個2 char('''''和'r')組合還是一個CR?嘗試'.replace(/ = \ r/g,「」)' –

+0

似乎有效,但它仍然是下一行。我想要它在同一行。 –

+1

然後還有其他換行符號。試試'.replace(/ = [\ r \ n] +/g,「」)' –

回答

0

你正則表達式 - /=\\r/g - 的=\r所有實例匹配

你似乎要刪除的所有實例。 10並在符號後換行。

使用

.replace(/=[\r\n]+/g, "") 

=[\r\n]+匹配=,和[\r\n]+比賽在字符類中定義的1個或多個字符,LF(換行碼元,\n)和CR(回車,\r)。

0

如果你想捕捉回車,以及,你需要在你的正則表達式中添加換行(\n)。

texts[i].replace(/=\\r\n/g, "") 

here看到它在行動。

0

這應該工作。

正則表達式:

(=\\r\n) 

const regex = /(=\\r\n)/gm; 
 
const str = `[ ' 
 
    "message": "WorldStage Supports Massive 4K Video Mapping at Adobe MAX=\\r 
 
with Christie Boxer 4K Projectors', 
 
    ' 
 
    "message": "Inside Track: Trading Focus on Shares of Adobe Systems In=\\r 
 
c. (ADBE)' ]`; 
 
const subst = ``; 
 

 
// The substituted value will be contained in the result variable 
 
const result = str.replace(regex, subst); 
 

 
console.log(result);

參見:https://regex101.com/r/nbUFtw/2

0

你可以做到這一點通過以下方式:

var text = '"message": "WorldStage Supports Massive 4K Video Mapping at Adobe MAX=\r with Christie Boxer 4K Projectors'; 
 

 
console.log(text.replace("=", "").replace("\\r", ""));