string – Regex – get everything between two characters based on input
The regex in JavaScript would look like this
const regex = /\(\(([^)]*)\)\)/
The actual code would be like this
const inputString = "Today is ((day|12pm))";
const regex = /\(\(([^)]*)\)\)/;
const matches = inputString.match(regex);
console.log(matches)
if (matches && matches.length > 1) {
const result = matches[1];
console.log(result); // Output: day|12pm
} else {
console.log("No match found");
}
As matches is containing the array of values. If there is a match then matches[1] extracts the content captured
Read more here: Source link
