Method 1, use string interception substring() and character position query indexOf();
string.substring(start,end) intercepts a string from string.
start: interception starting position.
end: intercept the end position.
string.indexOf(findstr), find the position of the specified string in string
findstr: the string you are looking for var?str1="aaa@hotmail.com"; //To intercept the content between @ and .
var?str2=str1.substring(str1.indexOf("@")+1,str1.indexOf("."));
console.log(str2);
Method 2, use regular expressions
[\@] matches @
[\.] matches .
.Match any character
+match the previous content one or more times
*match the signature content 0 or more times
The content in () can be replaced with $1, which is the part we are looking for
$1, $2,... can match () in the regular expression. The first bracket numbered in sequence is $1, the second bracket The ones digit is $2, and so on var?str1="aaa@hotmail.com";//To intercept the content between @ and .
var?reg=new?RegExp('.*[\ @]+(.*)[\.]+.*');
var?str2=str1.replace(reg,"$1");
console.log( str2);