Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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_Python 3.x - Fatal编程技术网

如何使用python提取特定文本

如何使用python提取特定文本,python,python-3.x,Python,Python 3.x,我有一个变量有值 ServerC = "WebSphere:cell=abc,cluster=Cluster1+WebSphere:cell=abc,cluster=Cluster2" 我只需要另一个变量中的所有集群值 我正在尝试使用 clusterN = ServerC.split("cluster=") clusterN = clusterN[1] 但是我没有得到所需的值您可以使用re.findall(): 你所说的U&L是什么意思?这与Linux中的Python脚本有关,“但我没有得到

我有一个变量有值

ServerC = "WebSphere:cell=abc,cluster=Cluster1+WebSphere:cell=abc,cluster=Cluster2"
我只需要另一个变量中的所有集群值 我正在尝试使用

clusterN = ServerC.split("cluster=")
clusterN = clusterN[1]

但是我没有得到所需的值

您可以使用
re.findall()


你所说的U&L是什么意思?这与Linux中的Python脚本有关,“但我没有得到所需的值”。你得到了什么?你想要什么?
import re
ServerC = "WebSphere:cell=abc,cluster=Cluster1+WebSphere:cell=abc,cluster=Cluster2"
pat = re.compile("cluster\=(\w+)")
print(pat.findall(ServerC))

# Output: ['Cluster1', 'Cluster2']