我有以下代码:
pattern = "something.*\n" #intended to be a regular expression
fileString = some/path/to/file
numMatches = len( re.findall(pattern, fileString, 0) )
print "Found ", numMatches, " matches to ", pattern, " in file."
Run Code Online (Sandbox Code Playgroud)
我希望用户能够看到模式中包含的'\n'.此时,模式中的'\n'会在屏幕上写入换行符.所以输出如下:
Found 10 matches to something.*
in file.
Run Code Online (Sandbox Code Playgroud)
我希望它是:
Found 10 matches to something.*\n in file.
Run Code Online (Sandbox Code Playgroud)
是的,pattern.replace("\n","\n")确实有效.但我想要它打印所有形式的转义字符,包括\ t,\ e等.任何帮助表示赞赏.
| 归档时间: |
|
| 查看次数: |
48261 次 |
| 最近记录: |