const regex = /"name"\:"(.*?)"/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('"name"\\:"(.*?)"', 'gm')
const str = `{"responseheader":{"status":0,"qtime":0},"initfailures":{},"status":{"alfresco":{"name":"alfresco","instancedir":"/opt/alfresco-search-services/solrhome/alfresco","datadir":"/opt/alfresco-search-services/solrhome//alfresco/","config":"solrconfig.xml","schema":"schema.xml","starttime":"2021-08-19t02:12:04.560z","uptime":8396697412,"index":{"numdocs":6530,"maxdoc":6567,"deleteddocs":37,"indexheapusagebytes":-1,"version":8008,"segmentcount":7,"current":true,"hasdeletions":true,"directory":"org.apache.lucene.store.nrtcachingdirectory:nrtcachingdirectory(mmapdirectory@/opt/alfresco-search-services/solrhome/alfresco/index lockfactory=org.apache.lucene.store.nativefslockfactory@17aaa8c6; maxcachemb=48.0 maxmergesizemb=4.0)","segmentsfile":"segments_16t","segmentsfilesizeinbytes":553,"userdata":{"committimemsec":"1634259620015"},"lastmodified":"2021-10-15t01:00:20.015z","sizeinbytes":7442643,"size":"7.1 mb"}},"archive":{"name":"archive","instancedir":"/opt/alfresco-search-services/solrhome/archive","datadir":"/opt/alfresco-search-services/solrhome//archive/","config":"solrconfig.xml","schema":"schema.xml","starttime":"2021-08-19t02:12:04.556z","uptime":8396697416,"index":{"numdocs":4206,"maxdoc":4218,"deleteddocs":12,"indexheapusagebytes":-1,"version":7901,"segmentcount":6,"current":true,"hasdeletions":true,"directory":"org.apache.lucene.store.nrtcachingdirectory:nrtcachingdirectory(mmapdirectory@/opt/alfresco-search-services/solrhome/archive/index lockfactory=org.apache.lucene.store.nativefslockfactory@17aaa8c6; maxcachemb=48.0 maxmergesizemb=4.0)","segmentsfile":"segments_14m","segmentsfilesizeinbytes":489,"userdata":{"committimemsec":"1634259610017"},"lastmodified":"2021-10-15t01:00:10.017z","sizeinbytes":801540,"size":"782.75 kb"}}}}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions