Optimizing Regular Expression
I have one regular expression which convert html to txt. But It is taking a lot of CPU usages . How开发者_高级运维 can I optimize it ?
((\n|\r){2,}) | (\r|\n)|<head.*?</head>|<script.*?</script> |<meta[^>]+>|<style.*?</style> | <[^>]*> |&[^\s]*;
Use an HTML parser if you can. Regex is bad for HTML for various reasons, and performance will inevitably suffer as well.
精彩评论