Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将regexp添加到yaml python_Python_Regex_Yaml - Fatal编程技术网

将regexp添加到yaml python

将regexp添加到yaml python,python,regex,yaml,Python,Regex,Yaml,有没有办法使用python在YAML中存储和读取此regexp: regular: /<title [^>]*lang=("|')wo("|')>/ 我的代码: def test2(): clueAppconf = open('test.yaml') clueContext = yaml.load(clueAppconf) print clueContext['webApp'] 好的,看起来问题在于您选择了什么类型的标量来表示这个正则表达式。如果

有没有办法使用python在YAML中存储和读取此regexp:

regular: /<title [^>]*lang=("|')wo("|')>/ 
我的代码:

def test2():
    clueAppconf = open('test.yaml')
    clueContext = yaml.load(clueAppconf) 
    print clueContext['webApp']

好的,看起来问题在于您选择了什么类型的标量来表示这个正则表达式。如果您使用的是标量(yaml字符串),则需要使用双引号标量和转义码来处理它阻塞的特殊字符。因此,您的yaml应该如下所示:

regular: "/<title [^>]*lang=("\x7C')wo("\x7C')>/" 
regular: "/<title [^>]*lang=("\u007C')wo("\u007C')>/"
regular:“/]*lang=(“\x7C”)wo(“\x7C')>”
为了保持可读性,我只跳过了它所阻塞的字符,但是根据它是否抛出更多错误,您可能需要跳过其他字符。此外,还可以使用unicode转义码。看起来是这样的:

regular: "/<title [^>]*lang=("\x7C')wo("\x7C')>/" 
regular: "/<title [^>]*lang=("\u007C')wo("\u007C')>/"
regular:“/]*lang=(“\u007C”)wo(“\u007C')>”

我对yaml的知识有点缺乏,所以我不知道如何在yaml中保持特殊字符及其可读性。根据我对yaml文档的粗略扫描,这是我能找到的最好的文档。

您到底想做什么?将正则表达式存储在yaml中?从yaml读出来?使用它搜索yaml流?那么,您是否有任何代码尝试执行此操作并且阻塞/失败?