Skip to content

Instantly share code, notes, and snippets.

@rj-hwang
Created January 16, 2017 02:04
Show Gist options
  • Save rj-hwang/64ec67c3720915bffb2ffde72b6048d9 to your computer and use it in GitHub Desktop.
Save rj-hwang/64ec67c3720915bffb2ffde72b6048d9 to your computer and use it in GitHub Desktop.
js 正则获取 innerText
var src = 'AAA <a href="https://baidu.com">abc<b>中国</b>123</a>'
var text = src.replace(/<.*?>/ig, '')
// or
var text = src.replace(/(<([^>]+)>)/ig, '')
// result:text="AAA abc中国123"
// ref: http://stackoverflow.com/questions/2622903/regex-how-to-get-contents-from-tag-inner-use-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment