我想要trim掉左边的`# ==` 和右边的`==`,请问js如何做到呢?

我有如下格式的字符串们:
我想要trim掉左边的# == 和右边的==,

# == 3.This is b ==
# == 2.This is == a ==
# == 4.This is === c ==
# == 5.This is d ==

想要得到:

3.This is b 
2.This is == a 
4.This is === c 
5.This is d 

请问是否有方法可以得到呢?

回复
阅读 1.1k
3 个回答
`# == 3.This is b ==
# == 2.This is == a ==
# == 4.This is === c ==
# == 5.This is d ==`.replace(/(?<=\n|^)#\s*==\s*|\s*==\s*(?=\n|$)/g,'')
`# == 3.This is b ==
# == 2.This is == a ==
# == 4.This is === c ==
# == 5.This is d ==`.replace(/^# == |==$/gm, '')
let str = '# == 3.This is b =='
let newArr = str.split(' ').slice(2, -1).join(' ')
console.log(newArr)
推荐问题
宣传栏