引用(https://segmentfault.com/a/1190000013075245?utm_source=weekly&utm_medium=email&utm_campaign=email_weekly)php
先來個簡單的例子:segmentfault
$reg = /^(\d{4})[/-](\d{1,2})[/-](\d{1,2})$/; $reg.test('2018/01/01'); //return true; $reg.test('2018-01-01'); //return true;
種類markdown
1、字符類 []spa
$reg = /[abc]/; //匹配a或b或c
code
2、字符類取反 [^]blog
$reg = /[^abc]/; //匹配除a、b、c外的其餘字符string
3、範圍類[-]class
$reg=/[0-9]/; //0到9的數字test
4、預約義類email
5、量詞