问题
I'm using the htmlcompressor (https://code.google.com/p/htmlcompressor/#For_Non-Java_Projects) to minify HTML content (HTML email templates) as well as inline CSS within the head section of the document. I'm running this via Command Line on Windows:
java -jar /path/to/htmlcompressor --preserve-comments --preserve-line-breaks --compress-css --remove-surrounding-spaces min -p /path/to/minify-preserve.txt --type html original-html -o minified-output.html
Within this document there are two media queries which I need to prevent the htmlcompressor from modifying due to syntax issues. I was looking around and found this regex rule:
@media[^{]+\{([\s\S]+?})\s*}
It however matches the media queries and the contents between, ideally, I need it to match only the starting block and end brackets, so its maintains spaces in these areas for valid syntax.
Would this be achievable with regex? I am limited to regex only as its the only method of creating preservation rules, as per the documentation.
Thanks.
回答1:
You'r regular expresion is almost right. but (backward slash) is missing before closing curly brace
@media[^{]+\{([\s\S]+?\})\s*\}
来源:https://stackoverflow.com/questions/24183531/using-regex-to-match-the-start-and-end-of-a-media-query-but-not-the-content-inb