可以用正则的方法:
search() 找到匹配的第一个字符串,返回位置,文档
match() 提取匹配的字符串,返回子串,文档
replace() 替换全部匹配的字符串,文档
RegExp.test() 检测字符串是否和正则匹配,文档
两种正则定义方法
var re = new RegExp('a', 'i');
var re = /a/i;
常用规则
/*
* \d 数字
* \D 除了数字
* \w 英文数字下划线
* \W 除了英文数字下划线
* \s 空白字符
* \S 除了空白字符
* . 任意
*
* {n} 出现 n 次:如 \d{2} 表示 2 个数字
* {n,m} 出现 n~m 次:如 \d{2,4} 表示 2~4 个数字
* {n,} 最少出现 n 次
* + 若干个:如 \d+ 表示若干个数字
* ? 出现 0 或者 1 次:如 \d? 表示没有或者有一个数字
* * 出现 0 或者 多次,如 \d* 表示没有或者有一个/多个数字
* | 或者,如:1|2 表示 1 或者 2
* [] 或者,如 [abc] 表示 a 或 b 或 c
* [a-z0-9] 表示从 a 到 z 或者从 0 到 9
* [^a-z] 表示除了 a 到 z
*
* i 忽略大小写
* g 全局匹配
*
* ^ 行首
* $ 行尾
*
* () 小括号内优先
*
* */
一个在线验证正则表达式的网站
正则表达式30分钟入门教程
You made some decent points there. I looked on the internet for the difficulty and located most people will associate with with your website.
I like this web site so much, bookmarked. “American soldiers must be turned into lambs and eating them is tolerated.” by Muammar Qaddafi.
Your place is valueble for me. Thanks!…
Wonderful web site. A lot of helpful information here. I am sending it to a few pals ans also sharing in delicious. And certainly, thank you for your effort!
Thank you for sharing excellent informations. Your site is so cool. I’m impressed by the details that you?¦ve on this blog. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found simply the info I already searched all over the place and simply couldn’t come across. What a great web-site.
I like your writing style really loving this web site.
I’ve been absent for a while, but now I remember why I used to love this blog. Thank you, I will try and check back more often. How frequently you update your site?