用空格替换每个

时间:2017-05-08 18:31:58

标签: javascript regex

我使用谷歌地图从我传入的变量生成不同的位置。但是,我从API收到一个错误,说它无法找到地址,我想我知道为什么。这是因为我有一个<br/>标签用于输出的变量。

因此,例如,当我提醒正在传递的变量时,它看起来像这样:

Deep Forest <br/> Suite 233 <br/> 100 Top Lane <br/>洛杉矶,加利福尼亚州

但我希望输出的变量看起来像这样。

Deep Forest Suite 233 100 Top Lane洛杉矶,加利福尼亚州

简而言之,我只想用空格替换<br/>的所有实例。我有我所有不同的位置变量。

以下是我的尝试:

var content = ("cookie.current.addressLabel"); // this outputs the current location address which is Deep Forest<br/>Suite 233<br/>100 Top Lane<br/>Los Angeles, CA 
         var text = $(content).text();
        //showGoogleMap(content);
        var regPat = /<br\s*[\/]?>/gi;

2 个答案:

答案 0 :(得分:1)

一个简单的替换应该做的伎俩。不需要正则表达式。

text.replace('<br/>', ' ');

答案 1 :(得分:0)

尝试

var content = ("cookie.current.addressLabel"); // this outputs the current location address which is Deep Forest<br/>Suite 233<br/>100 Top Lane<br/>Los Angeles, CA 
         var html= $(content).html();
        //showGoogleMap(content);
        html.replace( /<br\s*[\/]?>/gi, ' ');
相关问题