[英]Regex that matches anything between ' '
Please can you help me about this: 请您帮我一下:
consider the following line: 考虑以下行:
"Duplicate entry 'blah@gmail.com' for key 'email'"
I need a regex that matches any thing between ' ' incloding white spaces, new lines, and also any ' character between ' ' 我需要一个正则表达式来匹配''之间包含空格,换行和'之间的任何'字符
the code im using is: (Python) 我使用的代码是:(Python)
value = "Duplicate entry 'blah@gmail.com' for key 'email'"
dict = re.findall(r'regex goes here', value)
print dict[0]
print dict[1]
i need to print: 我需要打印:
blah@gmail.com
email
>>> m = re.match("Duplicate entry '(?P<value>.*)' for key '(?P<key>.*)'", "Duplicate entry 'blah@gmail.com' for key 'email'")
>>> m.group('value')
'blah@gmail.com'
>>> m.group('key')
'email'
string = "Duplicate entry 'blah@gmail.com' for key 'email'"
pattern = re.compile("'[^']*'")
matches = pattern.findall(string)
# matches == ["'blah@gmail.com'", "'email'"]
If you want to force the quotes to have at least one character in them: 如果要强制引号中至少包含一个字符:
pattern = re.compile("'[^']+')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.