This question already has answers here:
Regex to match only letters
(20 answers)
Closed 3 years ago.
I need to find regex pattern for url and use regex.test() so only string like this:
http://*.margonem.pl/
so it's exactly like above string and where * must appear and can be string which only contains a-z letters without any signs.
That would be http:\/\/[a-z]+\.margonem\.pl\/:
Matches
http://a.margonem.pl/
http://foo.margonem.pl/
Does not match
http://hello-world.margonem.pl/
http://abcq443435u4531.margonem.pl/
Related
This question already has answers here:
Negating a backreference in Regular Expressions
(6 answers)
Closed 4 years ago.
Lets take:
stringi = 'xnxx xnnx xnnxn'
My regex is: (n)[^n]
I want to make my regex a little more dynamic like that:
(n)[^\1] -\1 beeing the capt. grp 1
My desired result would be that:
(n)[^\1] would be equal (n)[^n]
(x)[^\1] would be equal (x)[^x]
How can I not match a NOT-\1 character?
using a negative lookahead, the . is to match any character as n length is one
(n)(?!\1).
This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 5 years ago.
I'm trying to write a regex to blacklist certain words. I'm able to create a whitelist like /^(carrots|onions|corn)$/ but how would I convert that into a blacklist?
Edit: To clarify, I'm matching this blacklist against a whole string. For example "corndog" should be allowed. I want the regex equivalent of blacklistArray.indexOf(word) === -1
Use negative lookahead:
^(?!.*(?:carrots|onions|corn))
This question already has answers here:
Regular expression to limit number of characters to 10
(6 answers)
Closed 6 years ago.
I need regex for validating alphanumeric String with length of 6 chars. I tried with following regex And done it for allowing alphanumeric chars but don't know how to stop exceeding more than six chars.
var regex = new RegExp("^[a-zA-Z0-9\b]+$");
Fiddle here.
you just have to add {6} in the end
var regex = new RegExp('[a-zA-Z0-9\b]{6}$'); You can test it out here https://regex101.com/
This question already has answers here:
A regular expression to exclude a word/string
(7 answers)
Closed 7 years ago.
I am trying to write a regex that accepts url with pathname of the form
/exmaple/XXXXX
Here,XXXXX can be a string of alphanumeric keywords but it should not be "create" or "add".
I have created the regex for accepting alphanumeric but I am unable to find a way to add exceptions of "create" or "add".
The negative lookahead is your friend, foo(?!pattern) means foo will not match if pattern matches immediately after foo. Like other lookarounds, negative lookaheads are not capture groups.
/\/example\/(?!create|add)[A-Za-z0-9]+/
This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 8 years ago.
I have this regex expression var re = /(?:\d{3}|\(\d{3}\))([\w-\/\.]?)\d{3}\1\d{4}/;, however, the \w whitespace doesn't work on this test console.log(re.test('123 456 7890'));
Here is my jsfiddle: http://jsfiddle.net/Bqb22/
You shouldn't use \w for whitespace. Use \s instead. (\w is word character, the same as [0-9A-Za-z_], and should not be used to indicate whitespace).