2017-02-16 127 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", ""));