0

как получить из строки только цифры и точку между числами например - Код 22.50 - результат должен быть 22.50, это текст записываеться в textarea как можно чтобы когда получались только числа и после каждый код был с абзаца

$(document).on("click", "#btnCopy", function() {
        var selectCont = document.querySelector('#codesList'),
            liActive = selectCont.querySelectorAll('li'),
            index = 0,
            copyField = document.getElementById('copyCode'),
            arr = [];
        copyField.innerHTML = "";
        for(index; index < liActive.length; index++) {
            var name = liActive[index].querySelector('.list-name'),
                text = name.textContent,
                template = text + " ";
            arr.push(template);
        }
        copyField.style.display = 'block';
        for (var n = 0; n < arr.length; n++) {
            copyField.insertAdjacentHTML('beforeend', arr[n]);
        }
        $("#copyCode").focus().select();
        var x = $("#copyCode").focus().select();
        document.execCommand("copy");
    });

2 ответа 2

1

С помощью регулярки /\d+\.\d+/.exec('Код 22.50')

0

str = "код 37.49";
re = /[0-9/.]+/

found = str.match(re)
console.log(found)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.