This question already has answers here:
Regex for not containing consecutive characters
(4 answers)
Closed 7 months ago.
My pattern is
^[a-z0-9][a-z0-9\-_.]*[a-z0-9\-_]$
I want to exclude one or more consecutive periods.
1.1.1.1 -----> GOOD
1..1.1.1 ------> BAD
Thank you for your help.
If just want to avoid any occurrence of dots being adjacent to each other, try the word boundary meta escape \b.
/\b[.]\b/g
RegEx101
Related
This question already has answers here:
Java Regular Expression to match dollar amounts
(6 answers)
Regular expression to match dollar amounts
(4 answers)
Closed 2 years ago.
Looking out first $ Symbols amount
$647.50 (Save $94)tried this code regular express: .match(/$(\d+)/);
But Does not working
OutPut Looking
647.50
[$](\d+).(\d+)
You have tried this it's working
This question already has answers here:
Regex Until But Not Including
(3 answers)
Closed 3 years ago.
I'm currently struggling with finding a way to extract domain names in urls.
My strings
xyz.weam.com
we2.wal.com
abc.workwork.google.net
I would like it to look for (com|org|net) and take the string before the match including the match until it hits the first (.) going backwards.
I have tried different combinations of lookbehind and positive lookahead but I was never able to make it stop at the right dot (.).
Thanks for the answers guys and especially to Aaron, his answer worked perfectly.
His Regex did the trick.
\.([^.]+).(?:com|net|org)$
This question already has answers here:
What is the JavaScript string newline character?
(15 answers)
Closed 6 years ago.
Can someone please explain to me what is a Line Terminator? I have trouble searching it online. It may be slightly irrelevant to the question but I would just like to know.
A line terminator is OS specific. This doesn't have anything to do with JavaScript. On windows a line is terminated by the control character sequence \r\n, On UNIX like systems, it is \n.
Recall that control characters aren't printable characters, so the \r and \n is conceptual, but usually they're put in string literals to represent the control character.
This question already has answers here:
Regular expression for first and last name
(28 answers)
Regex for names
(27 answers)
Closed 8 years ago.
I'm creating a web store and I need to validate inputs with JavaScripts so the user doesn't have to submit a form to be given the PHP errors (although I'm also validating the form with PHP).
What I came up with is the following regex:
/^[a-zA-Z]+$/
But the above regex would only allow alpha characters whereas I also want to allow characters such as ' and - since obviously names may also contain these two characters. My question is, how to make a regex to allow alpha characaters AND the two characters above.
Besides that I also have one more question which just came in my mind, characters such as ă will pass the above validation ?
By adding them to your character group like so
/^[a-zA-Z'-]+$/
This question already has answers here:
Count the number of occurrences of a character in a string in Javascript
(39 answers)
Closed 9 years ago.
Something similar to this, How to check if the URL contains a given string?
but is there a way to check if the URL contains a slash (/) more than 3 times, for example?
Thanks!
This is one possibility, all characters that are not "/" are removed, then the String.length is used to find how many characters remain.
Javascript
var url = "https://stackoverflow.com/questions/16449482/check-to-see-a-url-contains-a-certain-character-how-many-times";
console.log(url.replace(/[^\/]/g, "").length);
On jsfiddle
This is not the fastest method though, I just wanted to give an alternative to those that have already been suggested in a previous QA. I added it to the jsperf