常用正则表达式

由于在日常编程中,经常会遇到一些需要使用正则表达式的地方,可是有些网上又搜索不到,只好自己写,为了方便以后使用,我在这篇文章中,我会陆陆续续记录下来,不断维护更新

1. 匹配url扩展名

Regex:
(?<=/.)(/w+(?=/?)|(/w+)$)

Source:
http://www.baidu.com/index.html
http://www.sina.com/index.aspx?name=laszloyu&[email protected]

Matches:
html
aspx


2. 匹配url文件名(不包括扩展名)

Regex:
(/w+(?=/./w+$))|(/w+(?=/./w+/?))

Source:
http://www.baidu.com/index.html
http://www.sina.com/index.aspx?name=laszloyu&[email protected]

Matches:
index
index


你可能感兴趣的:(常用正则表达式)