Проблема с регулярным выражением

Поддержка
  • Всем привет, сделал регулярку. Вроде в группы сохраняет все правильно, но когда нужно все объединить выдает изначальный результат
    5ed06f64-46c6-44d9-99b5-dfd530fe7794-image.png
    1137f85d-8df6-496d-806e-4fb1ad5f1840-image.png
    в результате должно выходить 9004793970, но выходит изначальное число

  • regex is handled weird in bas, use raw nodejs code instead

  • Можно по другому
    Screen Shot 2024-08-11 at 01.11.26.png

    Screen Shot 2024-08-11 at 01.11.51.png

    или через кубик выполнить код:

    const phoneNumber = "+7 900 479-39-70";
    [[RESULT]] = phoneNumber.replace(/[^\d]/g, '').slice(1);
    
  • 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);

    спасибо большое! кубиком все вышло!