Tag: regex

What does this regex code means

There is a regex in my project,and i am trying to understand what does it mean,so if any one can help me out /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/ and /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/ In first I know the first one ,but what does (.[_a-z0-9-]+)* this is doing and what does this do (.[a-z0-9-]+)*(.[a-z]{2,4})$ and in second what does this ?= is doing […]

How to replace all * characters in a string using a regular expression

I want to delete * characters if it is present in a string. This is my code but it’s not working. String.replace(/*/g ”)

Searching an array for values ending in certain characters in JavaScript

So Im looking for help for writing a simple function in javascript. What I am trying to do is create an array of 6 name and print only those ending in “ie” or “y”. Here is my code – any help is appreciated. It unfortunately never reaches the function 🙁 //An array of names var […]

Javascript Regex – Remove single spaces NOT double spaces

I need to remove singles spaces from a string but not double spaces. Using regex I’ve tried this, however it is invalid and I’m not sure how to fix it: \s+{1,1} This is what I want to achieve: Raw string: “Okay, let ’s get star ted, Bret t ” After regex replace (keeping the double […]

Javascript replace() regular expression too greedy

I am trying to sanitize an HTML input field. I want to keep some of the tags, but not all of them, so I can’t just use .text() when reading the element value. I am having a bit of trouble with a regular expression in JavaScript in Safari. Here’s the snippet of code (I copied […]

How to remove a specific special character from a string along with all Alphabets

I have s string which looks something like “USD $1,111.11″ Now i want this in the following format “1111.11” In short i want the letters “USD” , Dollar sign “$”, and the “,” sign removed So if i do .replace(‘/^\D+/g’,”); I get “1,111.11” And if i do .replace(‘/\D+/g’,”); I get “111111” So how can i […]

How to Properly Format a Regex in JavaScript

This question already has an answer here: Why this javascript regex doesn't work? 1 answer

Regexp: numbers and few special characters

I am buried in a RegExp hell and can’t find way out, please help me. I need RegExp that matches only numbers (at least 1 number) and one of this characters: <, >, = (exactly one of them one time). My reg. expression looks like this: ^[0-9]+$|^[=<>]{1}$ And I thought it should match when my […]

Simple RegEx wierd result

I am trying to replace all occurences of ‘S’ (capital S) with ‘.sss’ : For example the following line doesn’t even contain a capital S in it and it still replaces a lot : “MM/dd/yyyy EEEE hh:mm aa”.replace(new RegExp(‘S*’, ‘g’),’.sss’) The result is : “.sssM.sssM.sss/.sssd.sssd.sss/.sssy.sssy.sssy.sssy.sss .sssE.sssE.sssE.sssE.sss .sssh.sssh.sss:.sssm.sssm.sss .sssa.sssa.sss” Don’t have any Ideea .. (to test […]

Replace all occurrences of character except in the beginning of string (Regex)

I’m trying to get rid of all minuses/dashes in a string number, except the first occurrence. After fiddling with Regex (JavaScript) for half an hour, still no results. Does anyone know the fix? Given: -123-45-6 Expected: -123456 Given: 789-1-0 Expected: 78910