var str='abcdef'; alert((2, 5)); //Cde does not include the end positionalert((1));//bcdef1
var str='a*b*cd*ef'; alert(('*'));//Split characters1
var str='acef'; alert((‘a'));//0 Find character positionalert((‘f'));//3 alert((‘ce'));//1 alert((‘o'));//-1Match failure-1
Regular
var re=new RegExp('b', 'i'); //i does not consider upper and lower case//or var re=/b/i;var str='abcdef';//Swap b to B with the same result, if i is removed, it will not workalert((re));
var str='asdf 34 656 cvs33'; var re=/\d/g; alert((re));//3,4,6,5,6,3,3match Get matching item 1var str='asdf 34 656 cvs33'; var re=/\d+/g;//Global Match: g—g—global,+ means once or more timesalert((re));//34,656,33
var str='asdf 34 656 cvs33'; var re=/\d+/g; var re2=/\d/g; alert((re,'*'));//asdf * * cvs*; alert((re2,'*'));//asdf ** *** cvs**1
Remove sensitive words
var str='A villager in Henan Kaifeng haha' var re=/Henan|Kaifeng/g;//Remove sensitive words Henan or Kaifeng var re1=/Henan|Kaifeng/; alert((re,'*')); alert((re1,'*'))//没有去掉Kaifeng,Try the results yourself1
3.[] any character, range
[abc]
Example: o[usb]t—obt, ost, out
[a-z]、[0-9]
Example: id[0-9]——id0, id5
[^a](Excluding everything except a)
Example: o[^0-9]t—oat, o?t, o t
combination
[a-z0-9A-Z]
The above is what the editor introduces to you. String and regular expression operations. I hope it will be helpful to everyone. If you have any questions, please leave a message. The editor will reply to everyone in time!