const str= `
<div id="chart681759405592">
{{hi}}
<el-button type="primary" @click="showMsg">主要按钮111</el-button>
</div>
<script>
const age = 12
new Vue({
name:"v-custom",data(){
return {
hi:'666'
}
},
methods:{showMsg(){
console.log('this',this)
// this.$Router.push('/v-edit')
}},
el:"chart681759405592"})
</script>
`
我想匹配的结果是
`new Vue({
name:"v-custom",data(){
return {
hi:'666'
}
},
methods:{showMsg(){
console.log('this',this)
// this.$Router.push('/v-edit')
}},
el:"chart681759405592"})`
求个大佬写个正则匹配
str.match(/new Vue[\s\S]*(?=<\/script>)/)[0]
开头取
new Vue
,结尾要不包含(?=<\/script>)
,匹配中间的全部[\s\S]*