I have a very simple regex that does not appear to be working as it should. The desired outcome of my regex is that I use it alongside replaceAll to replace any character that is not a-z, A-Z, or 0-9 with nothing(""). I realize there are many questions about the same thing but I am new to regex and the ones I see in those questions are MUCH too complicated to help me debug my own. I even tried using regexr.com to help me to no avail.
Here is my regex:
s.replaceAll("^[^a-zA-Z0-9]+", "");
s.replaceAll("[^a-zA-Z0-9]+$", "");
I have tried many different things including variants of ^[^a-zA-Z0-9]+$
and ^[^a-zA-Z0-9]*
but none of them work properly. They all seem to leave trailing punctuation on words which it should not be doing. Any suggestions are greatly appreciated. Thank you.