在实际的工作中,replace方法是用的比较多的,然后我把我最近刚刚完成的项目用的replace的实例整理出来,
后端返回数据是html格式,如果显示到页面去格式化
<view style="color: #333333;" class="context" v-html="item.description.replace(/<[^>]+>/g, '')"></view>
下面这个正则的ios会出现文字重叠,上面这个方法是兼容ios的
<view class="context" v-html="item.description.replace(/\<img/gi, '<img style=max-width:100%;height:auto')"></view>
替换文字
element.name = element.name.replace(/兑换/g,"兑现")
替换符号
time_set[0].replace(/\-/g, "/")
去空格
匹配任何空白字符,包括空格、制表符、换页符
this.Parameter.address.replace(/^\s*/,"")