常用的 regex 正規表達式(定時更新)

紀錄一下自己常用到的正規表達式


網址:/(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig

網域: /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/ig

電子郵件:/^(([^<>()\[\]\.,;:\[email protected]\"]+(\.[^<>()\[\]\.,;:\[email protected]\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\[email protected]\"]+\.)+[^<>()[\]\.,;:\[email protected]\"]{2,})$/i

排除(exclude)掉特定的字串: ^/(?!ignoreme|ignoreme2|ignoremeN)([a-z0-9]+)$

 

參考資料:

https://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string

Leave a Reply