這篇會慢慢增加內容,所以我也會更新發布日期。
JavaScript
var mac = /^\s*([\d[a-f]{2}:){5}[\d[a-f]{2}\s*$/i; var ip = /^((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))$/;
C language
char *mac = "([[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}"; char *ip = "^(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))$";
-
參考資料
- http://en.wikipedia.org/wiki/Regular_expression
RegexOneLearn regular expressions with simple, interactive examples.
回覆刪除http://regexone.com/