Skip to content

Tag: regex

Regular Expression | Leap Years and More

I’ve recently been looking for a regular expression to do some client side date checking, and I haven’t been able to find one that can satisfy the following criteria: Has a range from 1800 – Now Performs proper date checking with leap years MM/DD/YYYY Form Invalid Date Checking (These constr…

JavaScript Regex to match a URL in a field of text

How can I setup my regex to test to see if a URL is contained in a block of text in javascript. I cant quite figure out the pattern to use to accomplish this EDIT: So the Pattern I have now works in regex testers for what I need it to do but chrome throws an error for the following

Split the sentences by ‘,’ and remove surrounding spaces

I have this code: Looks like the whole string has been matched, but where has “b” gone? I would rather expect to get: so that I can do m.shift() with a result like s.split(‘,’) but also with whitespaces removed. Do I have a mistake in the regexp or do I misunderstand String.prototype.m…

Javascript Regular Expression Remove Spaces

So i’m writing a tiny little plugin for JQuery to remove spaces from a string. see here my regular expression is currently [ ]+ to collect all spaces. This works.. however It doesn’t leave a good taste in my mouth.. I also tried [s]+ and [W]+ but neither worked.. There has to be a better (more con…

How can I put [] (square brackets) in RegExp javascript?

I’m trying this: And the replace doesn’t work, what am I doing wrong? UPDATE: I’m trying to remove any square brackets in the string, what’s weird is that if I do it works, but replace(/[]/g, ”); doesn’t. Answer It should be: You don’t need double backslashes () becau…

Convert hyphens to camel case (camelCase)

With regex (i assume) or some other method, how can i convert things like: marker-image or my-example-setting to markerImage or myExampleSetting. I was thinking about just splitting by – then convert the index of that hypen +1 to uppercase. But it seems pretty dirty and was hoping for some help with reg…

regex replace just the last charater of a string

This should be an easy one and I couldn’t find it anywhere. How do I replace just the last character of a string with a char from an array? Answer $ matches the end of a string, . matches any character But you should probably use string functions for this: