RegExp

The literal for a regular expression object is / ~ /. (Not both "/ ~ /" and "/ ~ /")
Regular expression objects have test() and exec() methods.
test() returns a boolean value by determining whether the string passed as an argument matches the regular expression.
exec() finds and returns a string that matches the regular expression in the string that was input as an argument.

var regExp = /Java/;
var testStr = "www.java-school.net is the best site to learn Java";
var retArr = regExp.exec(testStr);
alert(retArr[0]);

i flag

The string after the / at the end of the regular expression object is a flag.
If the i flag is added, it is not case sensitive.

var regExp = /Java/i;
var testStr = "www.java-school.net is the best site to learn Java";
var retArr = regExp.exec(testStr);
alert(retArr[0]);

g flag

If you use the g flag, you remember the last matching location, and the next time exec() is called, it will find the matching location from the next location.

var regExp = new RegExp('Java', 'gi'); // /Java/gi
var testStr = "www.java-school.net is the best site to learn Java";
var retArr = regExp.exec(testStr);
retArr = regExp.exec(testStr);
alert(retArr[0]);

The character between / and /

Number of times
* 0 times or more
+ More than once
? 0 or 1 time
. Exactly once
{} Curly braces are used to specify the number of times a character is repeated.(s{2} means ss)
var regExp = /Java-*/gi;
var testStr = "www.java-school.net is the best site to learn Java";
var retArr = regExp.exec(testStr);
retArr = regExp.exec(testStr);
alert(retArr[0]);
\ following ordinary characters are treated as promised special characters.
\ following special characters are treated as characters themselves.
\w It means a word, exactly alphabets, numbers and _.
\W Opposite \w
\d Numbers
\D Opposite \d, \D* means zero or more characters.
\s Space character
var regExp = /\s\*/g;
var testStr = "www.java-school.net *is *the *best *site *to *learn *JAVA";
var retStr = testStr.replace(regExp,'-');
alert(retStr);

The following is a form for membership.

<form id="signUp" action="signUp" method="post" onsubmit="return check()">
    Name <input type="text" name="name" />
	
    <!-- omit -->

</form>

Write the JavaScript code to check that the value for the name is only a whitespace character.

function check() {
	var regExp = /\s/g;
	var form = document.getElementById("signUp");
	var name = form.name.value;
	name = name.replace(regExp,"");
	if (name.length == 0) {
		alert("Invalid Name");
		return false;
	}
	return true;
}
Start (^) and End ($)
^ Means start, /^JAVA/ finds JAVA at the beginning.
$ $ Means end, /school$/ finds school at end.
If you want to match multiple characters, list them in []
[a-zA-Z] Find the alphabet
[0-9] Find the number
^ in [] If ^ is used in [], it means to exclude ~. [^0-9] is the same as \D
() Patterns enclosed in parentheses are matched and then remembered and their values are stored as an array.
The stored substrings are stored in $ 1, $ 2, ....
| Means "or"
a|b is a or b, a|b|c is a or b or c

You can get regular expressions for emails at http://regexlib.com
In the above site, find a regular expression, and create a JavaScript function that checks email and dates for validity.

var emailRegExp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
var dateRegExp = /^\d{4}\/\d{2}\/\d{2}/;

var email = "johndoe@gmail.org";
var signUpDate = "2018/4/21";

var check = emailRegExp.test(email);

if (check) {
	alert("Valid email");
} else {
	alert("Invalid email");
}

check = dateRegExp.test(signUpDate);

if (check) {
	alert("Valid registration date");
} else {
	alert("InValid registration date");
}
References