Reputation: 1430
I have a fairly long String
var str = "[FirmLegalEntity [firmLegalEntityCode=F2, name=Global Markets Limited, shortName=CMP, firmLeCodeShortName=null], FirmLegalEntity [firmLegalEntityCode=D7, name=BHG SINGAPORE LIMITED, shortName=CGL, firmLeCodeShortName=null]]"
I need all firmLegalEntityCode
s.
I've tried using Str.shift("=,")
but this gets nowhere near the desired output.
There is also the issue that other values in the string are surrounded by =
and ,
.
Upvotes: 0
Views: 45
Reputation: 177786
My version
var str = "[FirmLegalEntity [firmLegalEntityCode=F2, name=Global Markets Limited, shortName=CMP, firmLeCodeShortName=null], FirmLegalEntity [firmLegalEntityCode=D7, name=BHG SINGAPORE LIMITED, shortName=CGL, firmLeCodeShortName=null]]";
var leg = str.match(/firmLegalEntityCode\=.{2}/g).map(function(str) {
return str.split("=")[1]
});
console.log(leg)
Upvotes: 0
Reputation: 7385
Try a regex:
var re = /firmLegalEntityCode=([^,]*),/g;
var s = '[FirmLegalEntity [firmLegalEntityCode=F2, name=Global Markets Limited, shortName=CMP, firmLeCodeShortName=null], FirmLegalEntity [firmLegalEntityCode=D7, name=BHG SINGAPORE LIMITED, shortName=CGL, firmLeCodeShortName=null]]';
var m;
while (m = re.exec(s)) {
console.log(m[1]);
}
Upvotes: 2