Групи дозволяють захопити частину збігу:
const s = 'Замовлення від 15.03.2024 на суму 450 грн';
const [, day, month, year] = s.match(/(\d{2})\.(\d{2})\.(\d{4})/);
const [, sum] = s.match(/(\d+) грн/);
console.log(`День: ${day}, Місяць: ${month}, Рік: ${year}`);
console.log(`Сума: ${sum}`);
const s = 'Ціна: 1500грн, знижка: 200грн, підсумок: 1300грн';
const nums = s.match(/\d+(?=грн)/g).map(Number);
console.log(nums);
console.log(nums.reduce((a, b) => a + b, 0));
function parseCSVLine(line) {
const fields = [];
const re = /(?:"([^"]*)"|([^,]*))/g;
let match;
while ((match = re.exec(line)) !== null) {
if (match.index === re.lastIndex) re.lastIndex++;
fields.push(match[1] !== undefined ? match[1] : match[2]);
if (re.lastIndex >= line.length) break;
re.lastIndex++;
}
return fields.filter(f => f !== undefined);
}
console.log(parseCSVLine('Іван,28,Київ,"розробник, senior",true'));