How to change all external links to “nofollow” but only for Contributor role?

I am exactly looking for this question
I have found these codes to convert all links to Nofallow, can anyone change these codes according to the user’s role

https://www.codespeedy.com/relnofollow-for-all-external-links-in-wordpress-using-code/

tech