I have a variable like this:
metricName = '(WebSpherePMI\|jvmRuntimeModule:ProcessCpuUsage)|(WebSpherePMI\|threadPoolModule\|WebContainer:ActiveCount)|(GC Monitor\|Memory Pools\|Java heap:Percentage of Maximum Capacity Currently Used)|(GC Monitor\|Garbage Collectors\|(.*):GC Invocations Per Interval Count)|(GC Monitor\|Garbage Collectors\|(.*):GC Time Per Interval \(ms\))|(GC Monitor:Percentage of Time Spent in GC during last 15 minutes)'
I need to create a for loop and go though this metricName one at a time. For example, 1st (WebSpherePMI\|jvmRuntimeModule:ProcessCpuUsage) then (WebSpherePMI\|threadPoolModule\|WebContainer:ActiveCount) then (GC Monitor\|Memory Pools\|Java heap:Percentage of Maximum Capacity Currently Used) so forth. Delimeter is | but not this \|
I tried creating an array:
data[]
data.append(metricName.split('|'))
but it gives me array like this:
[['(WebSpherePMI\\', 'jvmRuntimeModule:ProcessCpuUsage)', '(WebSpherePMI\\', 'threadPoolModule\\', 'WebContainer:ActiveCount)', '(GC Monitor\\', 'Memory Pools\\', 'Java heap:Percentage of Maximum Capacity Currently Used)', '(GC Monitor\\', 'Garbage Collectors\\', '(.*):GC Invocations Per Interval Count)', '(GC Monitor\\', 'Garbage Collectors\\', '(.*):GC Time Per Interval \\(ms\\))', '(GC Monitor:Percentage of Time Spent in GC during last 15 minutes)']]
Any ideas how I could put this in an array?
str.replace()and replace all the\|with some special string. Then split by '|'. Then restore the '\|'-s by replacing the "special string".... Not beautiful and buggy workaround, hence I don't post it as an answer, but it may work most of the times if your special string is really special