我想要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 

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

阅读 2.4k
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)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏