I'm trying to find a regex to remove all leading/trailing spaces as well as all leading/trailing special characters.
If I have the string:
test = '~!#@$@ hello this is a #! test ^^#!^^ '
I'd like it to return as:
'hello this is a #! test'
So special characters and spaces in between the first and last letter are preserved, but all leading/trailing ones are cut out. Right now I have this:
test.replace(/[^a-zA-Z ]/g,"").replace(/^\s+|\s+$/g, "")
which returns:
'hello this is a test'
so it is removing all special characters and leading/trailing spaces. How can I preserve that "#!" between "a" and "test"?