1

I'm trying to remove lines matching pattern 'WAN ipv4-address' from textarea '#textarea'

$("#textarea").val().replace(/WAN ipv4-address/g, '')

So I think above will only remove 'WAN ipv4-address' pattern from lines (in fact it doesn't even do this one for me). How to remove lines based on matching pattern ?

2 Answers 2

2

You are using the return of .replace():

$("#textarea").val($("#textarea").val().replace(/WAN ipv4-address/g, ''));

Strings are immutable this will return a new String you must use the new String.

Sign up to request clarification or add additional context in comments.

Comments

1

If ou want to remove the whole line then add .* before and after.

$("#textarea").val().replace(/.*WAN ipv4-address.*/g, '')

If you want to assign it back.

$("#textarea").val($("#textarea").val().replace(/.*WAN ipv4-address.*/g, ''));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.