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
Tag: regex
Javascript – Match and parse Hsl color string with Regex
I’m trying to parse a hsl color string and get an hex color string from it. I tried using regex but can’t figure it out. How my regexp should be look like to match and parse a hsl color string to hue, saturation and value fileds. The input will be one of the belows; Thanks. Answer This is probably how
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
Removing leading whitespace from indented HTML source in pre/code tags
I currently have the following html within a pre-code block: It is indented within the html source for better structure within the document. How can I remove the leading whitespace? Through the use of javascript or is there a more simple method. Answer You may want to just change how it is output, but it is fairly simple to do
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
Replace multiple strings with multiple other strings
I’m trying to replace multiple words in a string with multiple other words. The string is “I have a cat, a dog, and a goat.” However, this does not produce “I have a dog, a goat, and a cat”, but instead it produces “I have a cat, a cat, and a cat”. Is it possible to replace multiple strings with
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