This one should work for most instances:
'/(?<!(href|HREF)=")(?P<displaytext>\b(?P<
protocol>https?|ftp)://(?
P<domain>[-A-Za-z0-9.]+))(?P<file>/[-A-Za-z0-9+
& #/%=~_|!:,.;]*)?(?
P<parameters>\?[-A-Za-z0-9+& #/%=~_|!:,.;]*)?/'
It'll skip of the text inside the anchor tag, and capture
the what you
want to keep in the back reference "displaytext".
It's based on a one of the stock regexes from my regex buddy
library
so it won't be too bad, but I'm still a newbie to regex so
it'll
probably need to be optimized.
joelbyrd wrote:
> I'm wondering the best way to take any given blog post,
search for
> links, and replace them with shortened versions
(showing part of the
> link, and shortening the rest with "...").
E.g. finding something
> like
>
> <a href="http://www.sldfkjkdf.com/asdflkjsdjf/aasdlfjlaksdfa
sdf/asdfd?
> asdfjfjl=sfasdfasd&asdfasdfasdfasdfdf">http://www.sldfkjkdf.com/
a>
> asdflkjsdjf/aasdlfjlaksdfasdf/asdfd?
> asdfjfjl=sfasdfasd&asdfasdfasdfasdfdf</a>
>
> and shortening this to
>
> <a href="http://www.sldfkjkdf.com/asdflkjsdjf/aasdlfjlaksdfa
sdf/asdfd?
> asdfjfjl=sfasdfasd&asdfasdfasdfasdfdf">http://www.sldfkjkdf.com/
a>
> asdfdf...</a>
>
> I'm using PHP.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|