function extractSubstrings(s: string): string[] | "" {
// Regular expression pattern to find substrings between single quotation marks
const pattern: RegExp = /'(.*?)'/g;
// Find all matches in the input string
const substrings: string[] = [];
let match: any;
while ((match = pattern.exec(s)) !== null) {
substrings.push(match[1]);
}
if (substrings.length === 0) {
return "";
}
return substrings;
}
const str: string = "TypeScript is a free and 'open-source' 'high-level' 'programming language'";
const result: string[] | "" = extractSubstrings(str);
console.log(result);
/*
run:
["open-source", "high-level", "programming language"]
*/