我在脚本中有一个if语句,以查看通过argparse给出的目录是否是UNC路径.但不会以尾随斜线结束.
import re
#dest is set by argparse. but for this purpose i'll set it manually.
#originally i was escaping each \ in dest. But I found that argparse left them alone.
dest = '\\server-name\folder\subfolder'
if re.match ('^\\+[\w\W]+', dest ) and not re.match( '^\\+[\w\W]+\\$', dest):
dest = dest + '\\'
Run Code Online (Sandbox Code Playgroud)
我一直在用ipython玩这个.第一个声明无法匹配.我在Komodo IDE中使用了RxToolkit,它将正则表达式显示为匹配.我试过这个webtool:http://www.pythonregex.com/ 也匹配.有任何想法吗?