str := "Gigabyte GA-B250M-DS3H (1,485)MSI B250M PRO-VD (MS-7A74) (1,199)MSI H110M PRO-VH PLUS (MS-7A15) (946)Asus H110M-K (816)Asrock B250M-HDV (807)MSI B250M PRO-VDH (MS-7A70) (667)MSI H110M PRO-VD (MS-7996) (663)"
reg, _ := regexp.Compile("\\(.*?\\)")
str = reg.ReplaceAllString(str, "")
str.match(/rgb\(.*\)/).pop().match(/\d+/g)
str.match(/rgb\((.*)\)/).pop().split(', ')
const capitalize = str => str.replace(/(^|\s|-)+\S/g, m => m.toUpperCase());
phone.value = phone.value.replace(/[^+0-9]/g, '').slice(0, 11);
const
text = 'Sport',
str = 'port';
console.log(text.replace(new RegExp(`(${str})`, 'g'), '#$1#'));
или есть что-то оптимальней ?
text.replace(str, `#${str}#`)
. Правда, в отличие от регулярки - множественную замену так сделать не получится. 3\d{2}
. Или ^3\d{2}$
. Или \b3\d{2}\b
. В зависимости от того, каковы входные данные, и что надо получить в результате. const ip = str.split(':', 1)[0];
const ip = str.slice(0, str.indexOf(':'));
const ip = str.match(/[\d.]+/).pop();
const ip = str.replace(/:.+$/, '');
const [ ip ] = /.+(?=:)/.exec(str);