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, "")
const isPositiveInteger = RegExp.prototype.test.bind(/^\d+$/);
// или
const isPositiveInteger = str =>
!(!str || str.replace(/\d/g, ''));
// или
const isPositiveInteger = str =>
Boolean(str) && !str.match(/\D/);Нужна именно регулярка, т.к. числа большой длины.
const isPositiveInteger = str =>
str !== '' && [...str].every(n => Number.isInteger(+n));
// или
function isPositiveInteger(str) {
for (const n of str) {
if (!'0123456789'.includes(n)) {
return false;
}
}
return str.length > 0;
}
// или
function isPositiveInteger(str) {
let result = !!str;
for (let i = 0; i < str.length && result; i++) {
const n = str.charCodeAt(i);
result = 47 < n && n < 58;
}
return result;
}
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}#`). Правда, в отличие от регулярки - множественную замену так сделать не получится.