应用正则表达式时避免创建空格

时间:2019-07-26 04:22:34

标签: node.js regex regex-group

我有以下正则表达式:

result = result.replace(/\@.playhouse== 'true' && /g,''); 

运行于

.playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')].checked]

在我的输出中,我确实得到了预期的响应,但是它在@之前创建了一个空格,如下所示

.playground[?( @.IsPoolAvailable=='true')].checked]

有没有一种方法可以通过只运行一个regex exp来创建该空间?   见下文:

.playground[?(@.IsPoolAvailable=='true')].checked]

1 个答案:

答案 0 :(得分:1)

您需要转义特殊字符,然后替换:

@\.playhouse\s*==\s*'true'\s+&&\s+

您将获得预期的输出:

enter image description here

Demo

相关问题