I'm doing some dual-posting to livejournal and to my own website, and I'm having trouble translating the <lj user> tags. Say I've got a string like this:
Code:
so...<lj user="user1"> and <lj user="user2"> came over to visit today.
And what I'd like to do is translate those <lj> tags into <a href> links, like so:
Code:
so...<a href="http://www.livejournal.com/users/user1">user1</a> and <a href="http://www.livejournal.com/users/user2">user2</a> came over to visit today.
My problem is that the regex I've been using matches the widest possible pattern, rather than the narrowest.
Code:
re.sub("lj user=\"(.*)\"", "a href=\"http://www.livejournal.com/users/\\1/\">\\1</a>", s)
where "s" is the string I described above. This gives
user1"> and <lj user="user2 as the first group, rather than just
user1, and needless to say that makes the HTML look really funny. Is there a supported flag which will let me tell Python to find the narrowest possible match, rather than the widest?
many thanks!