@FastSpace said in Проблема при многопоточной работе с ресурсом:
@sayado колличество элементов в ресурсе. Меньше чем x, ждать пока появится больше
?? как мне "ждать пока появится больше"?
regex is handled weird in bas, use raw nodejs code instead
you can do it like this also
function generateRandomPhoneNumber() {
const includeInternationalCode = Math.random() > 0.7; // 30% chance to include international code
const internationalCode = includeInternationalCode ? `+${Math.floor(Math.random() * 99) + 1}` : '';
const areaCode = (Math.floor(Math.random() * 8) + 2) +
'' +
Math.floor(Math.random() * 10) +
'' +
Math.floor(Math.random() * 10);
const centralOfficeCode = (Math.floor(Math.random() * 8) + 2) +
'' +
Math.floor(Math.random() * 9) +
'' +
Math.floor(Math.random() * 10);
let lineNumber = '';
for (let i = 0; i < 4; i++) {
lineNumber += Math.floor(Math.random() * 10);
}
const separators = ['-', '.', ' ', ''];
const separator = separators[Math.floor(Math.random() * separators.length)];
// Randomly decide on the format of the phone number
const formatOptions = [
`(${areaCode})${separator}${centralOfficeCode}${separator}${lineNumber}`,
`${areaCode}${separator}${centralOfficeCode}${separator}${lineNumber}`,
`${areaCode}${separator}${centralOfficeCode}-${lineNumber}`,
`${areaCode}${separator}${centralOfficeCode}.${lineNumber}`,
];
let phoneNumber = formatOptions[Math.floor(Math.random() * formatOptions.length)];
if (includeInternationalCode) {
const internationalSeparator = Math.random() > 0.5 ? ' ' : '-';
phoneNumber = `${internationalCode}${internationalSeparator}${phoneNumber}`;
}
if (Math.random() > 0.8) { // 20% chance to add an extension
const extension = 'ext. ' + Math.floor(Math.random() * 9000 + 1000);
phoneNumber += ` ${extension}`;
}
return phoneNumber;
}
console.log(generateRandomPhoneNumber());
@DreamTeam said in Проблема с регулярным выражением:
const phoneNumber = "+7 900 479-39-70";
[[RESULT]] = phoneNumber.replace(/[^\d]/g, '').slice(1);
спасибо большое! кубиком все вышло!