Skip to content
Advertisement

Tag: regex

Regex to match accept-language header

I am trying to match the following accept-language header field of a http request. The problem is in the last line. It should imho yield: What is wrong with my regex? Answer Your first capturing group matches everything that doesn’t contain dashes and stops at a dash -. In your last string you have no dash, so it matches the

Mobile Number Validation (Internationally)

i am trying to do Validation check on mobile number , somewhat similar to what gmail had implemented. Gmail signup page link but variation among the phone number across country is to much, so finding it difficult to frame a regex for this. i looked upon some of the q’s here , but they work for some country or a

Regexp javascript – url match with localhost

I’m trying to find a simple regexp for url validation, but not very good in regexing.. Currently I have such regexp: (/^https?://w/).test(url) So it’s allowing to validate urls as http://localhost:8080 etc. What I want to do is NOT to validate urls if they have some long special characters at the end like: http://dodo……. or http://dododo&&&&& Could you help me? Answer

Use dynamic (variable) string as regex pattern in JavaScript

I want to add a (variable) tag to values with regex, the pattern works fine with PHP but I have troubles implementing it into JavaScript. The pattern is (value is the variable): I escaped the backslashes: But this seem not to be right, I logged the pattern and its exactly what it should be. Any ideas? Answer To create the

How to remove the extra spaces in a string?

What function will turn this contains spaces into this contains spaces using javascript? I’ve tried the following, using similar SO questions, but could not get this to work. Is there a simple pure javascript way to accomplish this? Answer You’re close. Remember that replace replaces the found text with the second argument. So: Finds any number of sequential spaces and

remove last directory in URL

I am trying to remove the last directory part of an URL. My URL looks like this: https://my_ip_address:port/site.php?path=/path/to/my/folder. When clicking on a button, I want to change this to https://my_ip_address:port/site.php?path=/path/to/my. (Remove the last part). I already tried window.location.replace(//[A-Za-z0-9%]+$/, “”), which results in https://my_ip_address:port/undefined. What Regex should I use to do this? Answer Explanation: Explode by “/”, remove the last element

Regex to check whether string starts with, ignoring case differences

I need to check whether a word starts with a particular substring ignoring the case differences. I have been doing this check using the following regex search pattern but that does not help when there is difference in case across the strings. my case sensitive way: Answer Pass the i modifier as second argument: Have a look at the documentation

Advertisement