js正則斷言整理

jsoncode發表於2016-11-29

前人栽樹後人乘涼:https://segmentfault.com/a/11…
如:
匹配一個圖片 abc.jpg

如果只匹配除abc,不要.jpg如何匹配:

`abc.jpg`.match(/w+(?=.w+)/)[0]

如果只匹配.jpg,不要abc

`abc.jpg`.match(/(?!w+).w+/)[0];// .jpg
`1.jpg`.match(/(?<![a-z]).w+/)[0];// .jpg 不是小寫字母開頭的
`abc.jpg`.match(/(?<![a-z]).w+/);// null 不是小寫字母開頭的

相關文章