I am dealing with timezone's in Javascript and I need a regex that will extract everything, but the timezone name from it. For example, I have the timezone America/Argentina/Buenos_Aires
. I want to extract the America/Argentina
part with a regex. Currently I have this regex: tz.match(/.*?(?=\/|$)/i)[0]
which extracts everything to the first backslash which works for most timezones (America/Los_Angeles
), but not for all of them. How could I edit that regex so that it gets the string before the last value?
I'd personally suggest avoiding regular expressions for something like this, when simple string functions/methods would suffice admirably:
var stringVariable = 'America/Argentina/Buenos_Aires',
text = stringVariable.substring(0, stringVariable.lastIndexOf('/'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With