PDA

View Full Version : Regex Help(easy im just horrible with regex)



cerealtx
January 30th, 2009, 05:35 PM
okay so i have a link and i just want the end of the link

http://media.website.com/ca7ae5a12f295a3980b9f0d39ea34cfe/filename.flv, i managed to create a regex expression to get the link from a html source now i just wanna cut that link down even further to just get "filename.flv" any one help? a explanation as to whats going on would be awesome 2, the code is great but i want to understand aswell

geirha
January 30th, 2009, 06:37 PM
Since * is greedy, you can remove everything up to the last / fairly easily

.*/(.*)
group 1 should be filename.flv with the example url above.


$ echo 'http://media.website.com/ca7ae5a12f295a3980b9f0d39ea34cfe/filename.flv' | sed -r 's|.*/(.*)|\1|'
filename.flv

badperson
January 30th, 2009, 06:38 PM
one of these should work:

\/([^\.]+)\.(.*)$
\/([^\.]+)\.(flv|htm|html)$

kaibob
January 30th, 2009, 07:22 PM
It's not intended for the purpose but basename is another alternative:


$ basename http://media.website.com/ca7ae5a12f295a3980b9f0d39ea34cfe/filename.flv
filename.flv