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
Regex 如何将正则表达式从某物选择到除\以外的某物(反斜杠)_Regex - Fatal编程技术网

Regex 如何将正则表达式从某物选择到除\以外的某物(反斜杠)

Regex 如何将正则表达式从某物选择到除\以外的某物(反斜杠),regex,Regex,下面是示例文本。我需要选择整个句子,从OAuth OAuth_con开始,到结尾没有反斜杠。注意:下面的示例文本在堆栈溢出之间有反斜杠,防止我有反斜杠粘贴 示例文本: "oauth":"OAuth oauth_consumer_key=\"asd-asd-asd-\", oauth_nonce=\"asdasdjjasdasd\", oauth_signature=\"asdasd%sdfsdf\", oa

下面是示例文本。我需要选择整个句子,从OAuth OAuth_con开始,到结尾没有反斜杠。注意:下面的示例文本在堆栈溢出之间有反斜杠,防止我有反斜杠粘贴

示例文本:

"oauth":"OAuth oauth_consumer_key=\"asd-asd-asd-\", oauth_nonce=\"asdasdjjasdasd\", oauth_signature=\"asdasd%sdfsdf\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"234234\", oauth_version=\"1.0\""
输出:

OAuth oauth_consumer_key="asd-asd-asd", oauth_nonce="asdasdjjasdasd", oauth_signature="asdasd%sdfsdf", oauth_signature_method="HMAC-SHA1", oauth_timestamp="234234", oauth_version="1.0"
试试这个python代码

import re

test_string = """"
"oauth":"OAuth oauth_consumer_key=\"asd-asd-asd-\", oauth_nonce=\"asdasdjjasdasd\", oauth_signature=\"asdasd%sdfsdf\",
 oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"234234\", oauth_version=\"1.0\""
"""
regex = r"(\w*[^\\])"

pattern = re.compile(regex, re.IGNORECASE)
matched = pattern.findall(test_string)
print(''.join(matched))

```
Working so far...

https://i.stack.imgur.com/iTEEd.png
示例文本:“oauth”:“oauth oauth用户密钥=\“asd asd asd-\”,oauth nonce=\“asdasdjjasdasd\”,oauth签名=\“asdasd%sdfsdf\”,oauth签名方法=“HMAC-SHA1\”,oauth时间戳=“234234\”,oauth版本=“1.0\”,输出:oauth oauth oauth用户密钥=“asd asd asd”,oauth U nonce=“asdasd=”oauth SDSDSDF%,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“234234”,oauth_version=“1.0”