为什么正则表达式r“ <!-。?->”不能选择“ <!-\\\\ ---->”?

时间:2019-02-02 16:39:00

标签: python regex

未找到匹配项。谢谢!

import re

re_tag = re.compile(r"</.?>")
text = r"</\\\\>"
match = re_tag.search(text)
print(match)

2 个答案:

答案 0 :(得分:1)

您串Dim userRange As Range, d As Double, cell As Range 'added more variables Set userRange = Application.InputBox("Select a range", Type:=8) For Each cell In userRange.Cells d = cell.Value With cell.Font If d < 0 Then .FontStyle = "Comic Sans MS" .Size = 18 .Color = vbRed End If If d >= 0 And d <= 500 Then .Bold = True .Italic = True .Underline = True End If If d > 500 And d <= 1000 Then .FontStyle = "Monotype Corsiva" .Color = vbBlue ActiveCell.Underline = xlDouble ' is this right? End If If d > 1000 Then .FontStyle = "Arial" .Bold = True .Italic = True .Color = vbGreen 'this is being undone in the next line of code. .Color = vbWhite End If End With Next cell 包含4个字面反斜杠。您的正则表达式仅允许text/之间的单个可选字符。例如,它将 匹配由>r"</\>"创建的4个字符的字符串。

答案 1 :(得分:0)

您有您的表达改变这样的事情(当然我不知道你想用正则表达式究竟检查什么):

re_tag = re.compile(r"</.{0,4}>")

对于任何一个字符来说,都不到4个字符

或者这样:

re_tag = re.compile(r"<.*>")

如果您想要任何长度的东西