正则表达式Python在样式标记之间删除(\n\r包括)
我对regexp有点困惑,我得到了这个文本,它需要删除标签中的样式。我用这个regexp正则表达式Python在样式标记之间删除(\n\r包括),python,css,regex,Python,Css,Regex,我对regexp有点困惑,我得到了这个文本,它需要删除标签中的样式。我用这个regexp(.*),在这样一行上运行它,非常简单: <style>@page { size: 8.5in 11in; margin-right: 1in; margin-top: 0.5in; margin-bottom: 0.5in }</style> 使用s修改器 (?s)表示“单行模式”,使点匹配所有字符, 包括换行。Ruby或JavaScript不支持。在Tcl, (?s)还使插入符号
(.*)
,在这样一行上运行它,非常简单:
<style>@page { size: 8.5in 11in; margin-right: 1in; margin-top: 0.5in; margin-bottom: 0.5in }</style>
使用s修改器
(?s)表示“单行模式”,使点匹配所有字符,
包括换行。Ruby或JavaScript不支持。在Tcl,
(?s)还使插入符号和美元在字符的开头和结尾匹配
仅限字符串
或使用:
<style>([\s\S]*)<\/style>
([\s\s]*)
只需使用(?s)
(DOTALL)修饰符即可使点与换行符匹配
(?s)<style>(.*?)<\/style>
(?s)(*?)
使用此正则表达式,“.”不包括\n
((?:.|\n)*)
(?s)<style>(.*?)<\/style>
<style>((?:.|\n)*)<\/style>