I am trying to write a gsub for a regex match, but I imagine there’s a more perfect way to do this .
My equation :
ref.gsub(ref.match(/settings(.*)/)[1], '')
So that I can take this settings/animals, and return just settings.
But what if settings is null? Than my [1] fails as expected.
So how can one write the above statement assuming that sometimes settings won’t match ?
So that basically, if it finds the word, settings, than get rid of anything after it. But if it doesn’t, no worries.
Thanks!
Why not do the simplest possible thing that could work?