DEV Community

Cover image for Can I Use replace() method to autoreplace all the chosen strings within a user input box of text type in js?
S3RG1096
S3RG1096

Posted on

Can I Use replace() method to autoreplace all the chosen strings within a user input box of text type in js?

Let's say there is a long-*ss paragraph, and some words in it are issues to copyright, so custom replacements are needed to all strings in p or span tags. By the way, it can be also a user-inputted text that is to be changed to fit the rules. Now, can i create a function with replace() method, and, is it possible to change the strings automatically by ".onclick"-ing on ? Pls provide a fully functional code of both <!DOCTYPE html> '/html' and 'script' '/script'.

Top comments (3)

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Replace can take regex patterns.
This can happen on keyup.

I won't be providing any code sorry, but that's how you would solve it.

Collapse
 
pavelloz profile image
PaweÅ‚ Kowalski • Edited

Yep, replace with regexp is the way to go.

duck.com is your friend.

Collapse
 
s3rg1096 profile image
S3RG1096

thx!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.