如何使用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']