This article illustrates the way JS uses the Split function to segment strings according to multiple characters. Share to everyone for your reference. The specific analysis is as follows:
The split () function in JS can split the string according to the specified symbol. But if there are more than one split symbol in the string, JS split () function can also be competent, the answer is yes, JS split () function can be implemented through regular expressions of multiple separator string segmentation, The call is also simple, and the following is a detailed example.
The following code can be separated by commas by using the JS split method
var mystring = "A,b,c,d,e";
var myarray = Mystring.split (",");
If there is such a string: "Jb51.net,google.com,baidu.com_weibo.com_haotu.net",
We want to split the site address by commas and underscores, and refer to the following code:
var mystring = "Jb51.net,google.com,baidu.com_weibo.com_haotu.net";
var myarray = Mystring.split (/[,_]/);
I hope this article will help you with your JavaScript programming.