You may not understand the function of the text area for entering Twitter tweets.

The text area for tweeting changes automatically when you enter a link.
I want to reproduce this specification, but I don't understand the code.

How can you change the color when it automatically matches a regular expression like this? Please let me know because only algorithm is enough.