I am trying to remove the apostrophes from this string: “‘234324234234234236548723adf83287942′”. I am trying to use this: to try and get “234324234234234236548723adf83287942”. But I can’t seem to crack it. How do I remove the apostrophes (‘)? Answer Just use ‘ on it’s own with the global modifier: Alternatively, if the quotes are always at the start and end, you don’t
Tag: regex
How to validate the DateTime of MM/dd/yyyy hh:mm format?
I am using MaskedEditExtender for entering a datetime. I am unable to figure out how to validate it. Is there any Regular Expression for validating dates along with time MM/dd/yyyy hh:mm or any Javascript function ?? Answer THis will solve your issue:
RegEx to match stuff between parentheses
I’m having a tough time getting this to work. I have a string like: And I need regex or a method of getting each match between the parentheses and return an array of matches like: The regex I’m using is /((.+))/ which does seem to match the right thing if there is only one set of parenthesis. How can I
How to make this regex replace work on all characters, not just the first?
I’m trying to replace all spaces within a string with hyphens. I tried this: But it only replaces the first instance of a space and not the ones after it. What is the regex to make it replace all empty spaces? Answer try the g flag is key here. it means global replace, ie replace all
PO Box Regular Expression Validation
Here’s my code, but I can’t ever trigger the alert. Answer In javascript, you have to escape your slashes: Also, you could reduce your pattern a bit by using case-insensitive matching: Note: Your regex also matches on addresses such as: 123 Poor Box Road 123 Harpo Box Street I would suggest also checking for a number in the string. Perhaps
Improving regex for parsing YouTube / Vimeo URLs
I’ve made a function (in JavaScript) that takes an URL from either YouTube or Vimeo. It figures out the provider and ID for that particular video (demo: http://jsfiddle.net/csjwf/). It works, however as a regex Novice, I’m looking for ways to improve it. The input I’m dealing with, typically looks like this: 1) Right now I’m doing three separate matches, would
How to remove numbers from a string?
I want to remove numbers from a string: I want to replace the number 1 number and the question mark ?. It can be any number. I tried the following non-working code. Answer Very close, try: replace doesn’t work on the existing string, it returns a new one. If you want to use it, you need to keep it! Similarly,
Regular expression [Any number]
I need to test for “[any number]” in a string in javascript. how would i match it? Oh, “[” and “]” also need to be matched. so string like “[1]” or “[12345]” is a match. Non match: “[23432” or “1]” So for example: I need to replace input fields name: “items[0].firstname” to “items[1].firstname” thanks Answer UPDATE: for your updated question
javascript regular expression to check for IP addresses
I have several ip addresses like: 115.42.150.37 115.42.150.38 115.42.150.50 What type of regular expression should I write if I want to search for the all the 3 ip addresses? Eg, if I do 115.42.150.* (I will be able to search for all 3 ip addresses) What I can do now is something like: /[0-9]{1-3}.[0-9]{1-3}.[0-9]{1-3}.[0-9]{1-3}/ but it can’t seems to work
Javascript regular expression: remove first and last slash
I have these strings in javascript: and I would like to remove the first and last slash if it’s exists. I tried ^/(.+)/?$ but it doesn’t work. Reading some post in stackoverflow I found that php has trim function and I could use his javascript translation (http://phpjs.org/functions/trim:566) but I would prefer a “simple” regular expression. Answer “Replace all (/…/g) leading