Skip to content

Instantly share code, notes, and snippets.

@kristianfreeman
Created April 1, 2012 01:36
Show Gist options
  • Save kristianfreeman/2270379 to your computer and use it in GitHub Desktop.
Save kristianfreeman/2270379 to your computer and use it in GitHub Desktop.
regexing a utc timezone code

Trying to regex in ruby using this: /UTC\s.\d{4}/

This picks up both

UTC +0000 UTC -0800

The codebase I'm working with uses: /UTC\s\-?\d{4}/

Which picks up

UTC +0000 UTC -0800

The period isn't the best alternative, because it's going to pick up anything besides the acceptable +/-. Thoughts?

@kristianfreeman
Copy link
Author

Ah, good to know. I'll remove the pipe.

@nikhilbansal
Copy link

nikhilbansal commented Feb 9, 2018

Just modified ttscoff's expression to /UTC\s[+-]\d{4}$/ to validate the terminating character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment