I need to use a long string for testing regular expression. However, the test string is always altered by the inside quotation marks, which leads to the whole string seperetaed into several parts and some of them are not included into the string, and thus error occurred.
str1=r"row Id="7" PostTypeId="2" ParentId="4" \n
CreationDate="2008-07-31T22:17:57.883"\n
Score="49" ViewCount="0" Body="<p>An explicit cast to double i"
Would you pleae tell me how to tackle this? Thanks a lot.
Use a multiline string:
As long as your string doesn’t span multiple lines, you can also use an alternative quote character:
or (if you have both kinds of quotes inside your string) escape the quotes (but, as Ned Batchelder noted, then you can’t use a raw string anymore):