Since I am not very strong in JS, I ask for help. You need to remove the string from the textarea with a specific character. Example: remove the line with the character ":" from:
test test:123 It should work:
test Since I am not very strong in JS, I ask for help. You need to remove the string from the textarea with a specific character. Example: remove the line with the character ":" from:
test test:123 It should work:
test function filter() { var substring = document.getElementById('input').value; var textarea = document.getElementById('textarea'); var text = textarea.value; text = text.split('\n'); text = text.filter(function(row) { return (row.indexOf(substring) == -1) }) textarea.value = text.join('\n') } <textarea id="textarea" rows=5>test test:test test </textarea> <input id="input" value=":" /> <button onclick="filter()">filter</button> <html> <body> <textarea id=txt>test test:123</textarea> <script> old = document.getElementById('txt').innerHTML; // Регуляркой отрезаем всё, что после ":" document.getElementById('txt').innerHTML = old.replace(/:.*/, ''); </script> </body> </html> You need to take the contents of the textarea and make the str.replace of the unnecessary part (you can find it regularly).
var textarea = document.getElementById( 'my-text-area-id' ) var str_to_change = textarea.innerHTML; str_to_change = str_to_change.replace( /\w*:\w*/, '' ); // /\w*:\w*/g если нужна жадная регулярка. textarea.innerHTML = str_to_change // устанавливаем новое значение в textarea If you need an arbitrary character to replace
var rgxp = new RegExp( '\w*' + my_symbol + '\w*' ); str_to_change = str_to_change.replace( rgxp, '' ); console.log(document.querySelector('textarea').value.replace(/[^\n]*:[^\n]*\n?/g, '')) textarea { height: 5em; } <textarea>test test:test test test:test</textarea> Source: https://ru.stackoverflow.com/questions/572109/
All Articles