Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式Python在样式标记之间删除(\n\r包括)_Python_Css_Regex - Fatal编程技术网

正则表达式Python在样式标记之间删除(\n\r包括)

正则表达式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)还使插入符号

我对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>([\s\S]*)<\/style>
([\s\s]*)
只需使用
(?s)
(DOTALL)修饰符即可使点与换行符匹配

(?s)<style>(.*?)<\/style>
(?s)(*?)

使用此正则表达式,“.”不包括\n

((?:.|\n)*)

(?s)<style>(.*?)<\/style>
<style>((?:.|\n)*)<\/style>