Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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中检测html标记中的空格和特殊字符_Python_Html_Regex - Fatal编程技术网

如何在python中检测html标记中的空格和特殊字符

如何在python中检测html标记中的空格和特殊字符,python,html,regex,Python,Html,Regex,对于以下输入 I/O 1< img > '< input > I/O 1<' img > '< input > I/O 1“ I/O 1 我希望获得如下所示的所需输出,如果尝试,并且\s+,则应发生这种情况: import re s = "I/O 1< img > '< input >" s = re.sub(r"<\s+", "<",

对于以下输入

I/O 1<   img   >    '<    input   >
I/O 1<'   img   >    '<    input   >
I/O 1
I/O 1
我希望获得如下所示的所需输出,如果
尝试
,并且
\s+
,则应发生这种情况:

import re

s = "I/O 1<   img   >    '<    input   >"
s = re.sub(r"<\s+", "<", s)
s = re.sub(r"\s+>", ">", s)
s = re.sub(r">\s+", ">", s)
print(s)
重新导入
s=“I/O 1“
s=re.sub(r“”,s)
s=re.sub(r“>\s+”,“>”,s)
印刷品
输出:

I/O 1'
s=“I/O 1

使用s.Find查找html标记的开头('我已经定义了starttagopen=re.compile('a-zA-Z')),我如何修改以拥有以上内容code@Venu我不明白。如果你已经有了你尝试过的代码,请编辑你的问题并将其包含在那里。嗨,空格,特殊字符可以是任意长度。谢谢你的回答。主要目的是在后面修剪空格,特殊字符“嗨,我刚做了一个编辑。从‘请’的索引开始,解释这如何帮助解决用户的问题。
import re

s = "I/O 1<   img   >    '<    input   >"
s = re.sub(r"<\s+", "<", s)
s = re.sub(r"\s+>", ">", s)
s = re.sub(r">\s+", ">", s)
print(s)
I/O 1<img>'<input>
s= "I/O 1<   img   >    '<    input   >"
( s[0:s.find('<')] ) + ( s[s.find('<'):].replace(' ','') )