Blog

JavaScript – RegExp To Validate Any Date

If you want to validate virtually any date (formatted as YYYY/MM/DD or YYYY-MM-DD) in JavaScript with a regular expression, you can use the following (fixed on August 8, 2013): /^(?!(?![02468][048]|[13579][26]00)..(?!(?!00)[02468][048]|[13579][26])...02.29)\d{4}([\/-])(?=0.|1[012])(?!(0[13578]|1[02]).31|02.3)\d\d\1[012]|3[01]$/ This was actually inspired by the regular expressions from this post. Of course, the best way to check a date’s Read more…

By Chris West, ago
Blog

PostgreSQL – Escape Regular Expressions

Someone had an issue today where they were using a string as if it were a regular expression. Not totally understanding what the desired end result would be, I had suggested they use something equivalent to Java’s Pattern.quote() function. It turned out that they really just wanted to determine if Read more…

By Chris West, ago
Blog

Regular Expression Examples

One of the things that I love about string manipulation is the existence of regular expressions. For this reason, I have decided to share a few examples that may help those who are learning about regular expressions so that can understand them a bit better. JavaScript – General Variable Name Read more…

By Chris West, ago
Blog

JavaScript Snippet – RegExp.prototype.clone()

There have been many times when I needed to simply modify the flags (options) for a regular expression in JavaScript. Unfortunately, the global, ignoreCase, multiline, and sticky (for FireFox) flags are immutable. In addition, when creating a new regular expression from an old one, you can’t supply a regular expression Read more…

By Chris West, ago