Skip to content
Advertisement

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 constraints were outside of my scope and are a requirement as

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.match? Answer so finally i went with /(?=S)[^,]+?(?=s*(,|$))/g, which

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 concise) way of searching

Split large string in n-size chunks in JavaScript

I would like to split a very large string (let’s say, 10,000 characters) into N-size chunks. What would be the best way in terms of performance to do this? For instance: “1234567890” split by 2 would become [“12”, “34”, “56”, “78”, “90”]. Would something like this be possible using String.prototype.match and if so, would that be the best way to

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 () because it’s not a string but a regex statement, if you build the

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 regex that could make the code cleaner. No jQuery…

Removing all script tags from html with JS Regular Expression

I want to strip script tags out of this HTML at Pastebin: http://pastebin.com/mdxygM0a I tried using the below regular expression: But it does not remove all of the script tags in the HTML. It only removes in-line scripts. I’m looking for some regex that can remove all of the script tags (in-line and multi-line). It would be highly appreciated if

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:

Advertisement