var user='xia&&min**'; user=(/[^A-Za-z\d_-]+/,''); //Add value again(user); //xiamin** user = (/[^A-Za-z\d_-]+/g, ''); //Replace globally(user); //xiamin
Split email
var email='nettuts@'; var result=(/([A-Za-z_\d-]+)@([A-Za-z_\d-]+)\.[a-z]{2,4}/ig,'$1,$2'); (result); //nettuts tutsplus
This method takes a single string parameter and returns a Boolean value indicating whether a criticism was found. If you don't need to operate on specific matching results, for example, verifying the username, the "test" method is enough to complete this task.
var name='xiamin'; var result=/[A-Za-z-_]+/.test(name); (result);
Unlike the test method, match() returns an array containing all the found criticisms.
var name='xiamin'; var result=(/i/g); (result); //(2) ["i", "i"]
Match all before and after question marks
var url ='http://localhost:8080?name=xiamin'; var result=(/^(.+)\?(.+)/i); (result);//"http://localhost:8080?name=xiamin?" "http://localhost:8080" "name=xiamin"
Match the content after #
var url ='http://localhost:8080?name=xiamin#dnsjdnw'; var result=(/#(.+)/i); (result);//"#dnsjdnw", "dnsjdnw"
Obtain the Agreement
var url ='http://localhost:8080?name=xiamin#dnsjdnw'; var result=(/(ht|f)tps?:/i); (result);//"http:", "ht"
Match the page url
var url =''; var result=(/.+\.[a-z]{2,4}/ig); (result);//
The above is a simple and practical example of JavaScript regular expressions introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!