简体   繁体   中英

how to remove inline css from string in javascript

I want to remove inline css from string in javascript:

var str = "p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'}
span.Apple-tab-span {white-space:pre} This is sample text";

I want

str = "This is sample text";

Could you please help me how to do this?

Thanks

If your string has always this pattern: The text after a css definition, you can try this:

const str = "p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'} span.Apple-tab-span {white-space:pre} This is sample text"

const lastOccurrence = str.lastIndexOf('}')

console.log(str.substr(lastOccurrence+1, str.length))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM