python - Properly escaping quotations within a string -
python - Properly escaping quotations within a string -
i have regex supposedly be-all-end-all detecting html tags. found here:
http://haacked.com/archive/2004/10/25/usingregularexpressionstomatchhtml.aspx/
the original regex below:
</?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>
when add together single quotes around it, becomes:
'</?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>'
but leaves inner part ('.\*?')
different entity string want make. ideas how prepare this? escaping inner quotes around .*? doesn't seem help since eol while scanning string error
any ideas?
you can utilize double quotes quote entire regex.
>>> obj = re.compile(r"</?\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>") >>> obj.pattern '</?\\w+((\\s+\\w+(\\s*=\\s*(?:\\".*?\\"|\'.*?\'|[^\'\\">\\s]+))?)+\\s*|\\s*)/?>'
note have escaped double quotes within regex \"
python regex string
Comments
Post a Comment