Skip to content
Advertisement

Tag: regex

Why does this regex replace remove a symbol at the start, but not at the end?

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

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

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

Advertisement