261,161 questions
5469
votes
78
answers
4.9m
views
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...
5468
votes
35
answers
5.5m
views
Regular expression to match a line that doesn't contain a word
I know it's possible to match a word and then reverse the matches using other tools (e.g. grep -v). However, is it possible to match lines that do not contain a specific word, e.g. hede, using a ...
4309
votes
78
answers
2.8m
views
How can I validate an email address using a regular expression?
Over the years I have slowly developed a regular expression that validates most email addresses correctly, assuming they don't use an IP address as the server part.
I use it in several PHP programs, ...
2498
votes
18
answers
1.3m
views
What is a non-capturing group in regular expressions?
How are non-capturing groups, i.e., (?:), used in regular expressions and what are they good for?
2356
votes
36
answers
4.0m
views
RegEx match open tags except XHTML self-contained tags
I need to match all of these opening tags:
<p>
<a href="foo">
But not self-closing tags:
<br />
<hr class="foo" />
I came up with this and wanted to make ...
1976
votes
29
answers
1.4m
views
How do you use a variable in a regular expression?
I would like to create a String.replaceAll() method in JavaScript and think using a regex would be the most terse way to do it. However, I can't figure out how to pass a variable into a regex. I can ...
1762
votes
24
answers
1.1m
views
How do you access the matched groups in a JavaScript regular expression?
I want to match a portion of a string using a regular expression and then access that parenthesized substring:
var myString = "something format_abc"; // I want "abc"
var arr = /(?:^|\s)format_(.*?...
1389
votes
3
answers
1.4m
views
Negative matching using grep (match lines that do not contain foo) [duplicate]
How do I match all lines not matching a particular pattern using grep? I tried this:
grep '[^foo]'
1352
votes
4
answers
111k
views
\d less efficient than [0-9]
I made a comment yesterday on an answer where someone had used [0123456789] in a regex rather than [0-9] or \d. I said it was probably more efficient to use a range or digit specifier than a character ...
1216
votes
15
answers
1.6m
views
Check whether a string matches a regex in JS
I want to use JavaScript (I can also use jQuery) to do check whether a string matches the regex ^([a-z0-9]{5,})$, and get a true or false result.
match() seems to check whether part of a string ...
1172
votes
10
answers
273k
views
Is there a regular expression to detect a valid regular expression?
Is it possible to detect a valid regular expression with another regular expression? If so please give example code below.
1092
votes
68
answers
772k
views
What is the best regular expression to check if a string is a valid URL?
How can I check if a given string is a valid URL address?
My knowledge of regular expressions is basic and doesn't allow me to choose from the hundreds of regular expressions I've already seen on the ...
1060
votes
46
answers
1.2m
views
How to validate phone numbers using regex
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it would handle international formats, but it must handle US formats, including the following:
1-234-567-8901
1-234-...
1041
votes
16
answers
1.3m
views
Regular Expressions: Is there an AND operator?
Obviously, you can use the | (pipe?) to represent OR, but is there a way to represent AND as well?
Specifically, I'd like to match paragraphs of text that contain ALL of a certain phrase, but in no ...
932
votes
45
answers
1.5m
views
Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
I want a regular expression to check that:
contains at least eight characters,
including at least one number and
includes both lower and uppercase letters and
include at least one special characters, ...