const regex = /^\(\p{Nd}\)\s+(.+)\n(\(\p{L}\).*?)।\s+Ans\s+\((\p{L})\)/gmu;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\(\\p{Nd}\\)\\s+(.+)\\n(\\(\\p{L}\\).*?)।\\s+Ans\\s+\\((\\p{L})\\)', 'gmu')
const str = `(1) Capital of Bangladesh is-
(A) Dhaka (B) Rangpur (C) Chittagong (D) Comilla। Ans (A) Dhaka
(2) Largest city of Bangladesh is-
(A) Mirpur (B) Rangpur (C) Chittagong (D) Comilla। Ans (C) Chittagong
(3) Smallest city of Bangladesh is-
(ক) বাংলা (খ) ইংরেজি । Ans (B) Rangpur`;
// 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