i have some strings like: I’m trying to write a regex that makes the first two string pass, but not the third one. The rule is that if the string contains the word “router” after the first dot and before the second dot it’s ok. i tried with but it match every .router. in my string, so also the third
Tag: regex
How would I make the html5 input to accept only email addresses from gmail.com using patter attribute?
I am using html input control to feed in email address. Also, I am using required attribute but I want the input should only be from gmail.com i.e. john@gmail.com, aamir@gmail.com etc and not any other domain. But this accept every domain and not only gmail.com. NOTE: I need to do it with regex in html5 control not with javascript etc
How to scrape
so I am trying to figure out how I can possible scrape a javascript tag using regex which I believe might be the easiest way. The tag looks like: and I want to scrape all Label Whaht I tried to do is: but it only returned an empty value of [] so I am here asking what can I do
Processing and replacing text inside double curly braces
I have a URL string: var url = https://url.com/{{query}}/foo/{{query2}} I have a line of code that is able to take in a string, then get an array of all the queries inside the braces: var queries = String(url).match(/[^{}]+(?=})/g); Returns: queries = [‘query’, ‘query2’] I have a function, parse(queries), which processes these queries and returns a list of their results: results
How do I use regex to match on a string that does not contain one of multiple specific words?
How do I use regular expressions to avoid matching strings containing one of multiple specific words? For example: a string should contain neither the words test, nor sample: My regular expression is failing in some situations: In the above two examples: It has the word test so it worked fine. It doesn’t have the word test it should be allowed
Remove currency symbol from string and convert to a number using a single line in Javascript
I have a string below that is a price in £, I want to remove the currency symbol and then convert this into a number/price I can use to compare against another value (eg. X >= Y …) £14.50 I have previously converted strings to numbers used for currency with var priceNum = parseFloat(price); IDEAL OUTCOME 14.50 as a number
Is it possible to interpolate Javascript regex match in a string template?
For example… (this fails) Is there a way to make this sort of thing work? $1 is available when it’s used in a string, but not as a key. Answer Unfortunately no, you’ll have to use a replacer function instead: Also note that you can use d instead of [0-9] instead, it makes the regex a bit nicer to read.
Matching whole words that start or end with special characters
I need a regular expression in javascript that matches whole words that start or end with special characters? It was supposed to be easy, but for some reason b after ? doesn’t behave as I expected: What I need, for instance if my word is “FOO?” (including the question mark), I want to match: “FOO? is cool”, “do you think
Works in Chrome, but breaks in Safari: Invalid regular expression: invalid group specifier name /(?<=/)([^#]+)(?=#*)/
In my Javascript code, this regex /(?<=/)([^#]+)(?=#*)/ works fine in Chrome, but in safari, I get: Invalid regular expression: invalid group specifier name Any ideas? Answer Looks like Safari doesn’t support lookbehind yet (that is, your (?<=/)). One alternative would be to put the / that comes before in a non-captured group, and then extract only the first group (the
Regex windows path validator
I’ve tried to find a windows file path validation for Javascript, but none seemed to fulfill the requirements I wanted, so I decided to build it myself. The requirements are the following: the path should not be empty may begin with x:, x:\, , // and followed by a filename (no file extension required) filenames cannot include the following special