const regex = /\((\w{0,3})\)\s([A-Z,a-z,\s]+)\((.*)\)?\s+([\d,.].*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\((\\w{0,3})\\)\\s([A-Z,a-z,\\s]+)\\((.*)\\)?\\s+([\\d,.].*)', 'gm')
const str = `Source: http://evds.tcmb.gov.tr/fame/webfactory/evdpw/rpt/1652.html
05-02-2016
(AUD) Avustralya Dolari (Doviz Alis) 2.08800
(AUD) Avustralya Dolari (Doviz Satis 2.10170
(BEF) Belcika Frangi (Doviz Alis) ..
(BEF) Belcika Frangi (Doviz Satis) ..
(BGN) Bulgar Levasi (Doviz Alis) 1.64750
(BGN) Bulgar Levasi (Doviz Satis) 1.66900
(CHF) Isvicre Frangi (Doviz Alis) 2.89220
(CHF) Isvicre Frangi (Doviz Satis) 2.91070
(EUR) Euro (Doviz Alis) 3.24060
(EUR) Euro (Doviz Satis) 3.24640
(RUB) Rus Rublesi (Doviz Alis) 0.03767
(RUB) Rus Rublesi (Doviz Satis) 0.03817
(USD) ABD Dolari (Doviz Alis) 2.90440
(USD) ABD Dolari (Doviz Satis) 2.90960`;
// 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