Test Regular Expression Patterns: https://regex101.com
Learn and find documentation: http://regexone.com
Detailed Documentation: https://msdn.microsoft.com/en-us/library/az24scfc%28v=vs.110%29.aspx
Name | Link |
---|---|
Nettuts - Using Regex in JavaScript | http://code.tutsplus.com/tutorials/you-dont-know-anything-about-regular-expressions-a-complete-guide--net-7869 |
Sitepoint - Regular Expressions in JavaScript | https://www.sitepoint.com/expressions-javascript/ |
Javscript.info - Regular expressions in JavaScript | http://javascript.info/tutorial/regular-expressions-javascript |
Flags
Abbreviation | Meaning |
---|---|
g |
global. All matches |
i |
insensitive. Case insensitive match (ignores case of [a-zA-Z]) |
Match any first three characters followed by a single period
...\.
// Matches: cat. OR 896. OR ?=+.
// Doesn't Match: abc1
Match any string that begins with any of a set of specified characters followed by other characters
[cmf]an
// Matches: can OR man OR fan
// Doesn't Match: pan
Match any substring that doesn't begin with a specified character followed by other characters
[^b]og
// Matches: hog OR dog
// Doesn't Match: bog
Match any substring that has characters between a range of numbers
[0-6]+
// Matches: 1234
// Doesn't Match: 897
Match any substring that has any alphanumeric characters within it
[\w]+
[A-Za-z0-9_]+
// Matches: george_12
// Doesn't Match: @#$%
Match any substring with a specified number of repetitions of a specified character or range of characters
In this case, it is looking for any repetitions of at least 2 or more of the character "o"
o{2,}
Match any characters that are repeated
https://regex101.com/r/cF6iI3/1
This way it will include all characters following each other that match the criteria and put them within the same match
\d+
// Matches: 12345
Match any characters that are optional
https://regex101.com/r/rW2cE2/1
files?
// Matches: file OR files
Match any characters that start with the given characters
https://regex101.com/r/sX0dS4/1
^Why hello there
Match any characters that start with the given characters and end after the given characters
https://regex101.com/r/qA3uQ6/1
Needs to be an exact match for the entire string
^Why hello there$
// Matches: Why hello there
// Doesn't Match: Why hello there Bob
Capture any characters that are surrounded by parantheses
https://regex101.com/r/nA7pY9/2
^(.+).pdf$
// Matches: file_07241999.pdf
// Doesn't Match: testfile_fake.pdf.tmp
Capture any characters that match either option
https://regex101.com/r/zL9rT6/1
I love (cats|dogs)
// Matches: I love cats OR I love dogs
// Doesn't Match: I love logs OR I love cogs
Match various ways to enter a US phone number and capture the area code, first 3 numbers, and the last 4 numbers
https://regex101.com/r/nU7jN6/1
[\(1]?\s?(\d{3})\)?[-\s]?([\d]{3})[-\s]?([\d]{4})
Find a match where the given substring is found anywhere within another string, and then capture the whole string
https://regex101.com/r/fX2dO2/1
((?:.*)(ling)(?:.*))
// Matches: linguist OR klingon OR sailing
// Doesn't Match: linting
Match various ways to enter an email address and capture the username, domain name with domain type, and the domain type by itself
https://regex101.com/r/sX5oW9/1
([\w\.\+\d]+)@([\w\.]+(?:\.([\w]{2,3})))