Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
Python 查找从斜杠到空格或字符的字符串_Python_Regex_Findall - Fatal编程技术网

Python 查找从斜杠到空格或字符的字符串

Python 查找从斜杠到空格或字符的字符串,python,regex,findall,Python,Regex,Findall,我想知道如何找到介于slach和括号或“]”之间的字符串,例如 data = "(AVP:SMTP/xx@xx.xx) R:AVP:SMS.0/+44648474 id:24" data2 = "(AVP:SMTP/<xxx@xx.xx>) R:AVP:FAX.0/<thisword> id:25" 但是它返回)和 我想要的是xx@xx.xx和这个词这个词很有效 import re data = "(AVP:SMTP/xx@xx.xx) R:AVP:SMS.0/+

我想知道如何找到介于slach和括号或“]”之间的字符串,例如

data = "(AVP:SMTP/xx@xx.xx) R:AVP:SMS.0/+44648474 id:24"
data2 = "(AVP:SMTP/<xxx@xx.xx>) R:AVP:FAX.0/<thisword> id:25"

但是它返回


我想要的是xx@xx.xx这个词

这个词很有效

import re

data = "(AVP:SMTP/xx@xx.xx) R:AVP:SMS.0/+44648474 id:24"
data2 = "(AVP:SMTP/<xxx@xx.xx>) R:AVP:FAX.0/<thisword> id:25"

regex = re.compile(r"/<?([^>\s\)]+)")

print regex.findall(data)
print regex.findall(data2)

>>> 
['xx@xx.xx', '+44648474']
['xxx@xx.xx', 'thisword']
重新导入
data=“(AVP:SMTP)/xx@xx.xx)R:AVP:SMS.0/+44648474 id:24“
data2=“(AVP:SMTP/)R:AVP:FAX.0/id:25”

regex=re.compile(r”/您可以使用以下方法排除此类分隔符:

k=re.findall(r“(?)”,数据2)

这将确保至少一次“
/
”,并在匹配后出现“
”时成功。

如果输入的子字符串是
/)
,你需要斜杠和括号之间的所有内容,显然这将包括
;如果你想排除这些内容,你需要在正则表达式中这样做。谢谢你,但是当有一个词在这两个词之间时,它找不到第二个词。Inbar Rose的解决方案很有效,谢谢你的帮助非常好的解释,非常感谢!!
import re

data = "(AVP:SMTP/xx@xx.xx) R:AVP:SMS.0/+44648474 id:24"
data2 = "(AVP:SMTP/<xxx@xx.xx>) R:AVP:FAX.0/<thisword> id:25"

regex = re.compile(r"/<?([^>\s\)]+)")

print regex.findall(data)
print regex.findall(data2)

>>> 
['xx@xx.xx', '+44648474']
['xxx@xx.xx', 'thisword']
k = re.findall(r"(?<=/<)[^>]+(?=>)",data2)