468,288 Members | 1,963 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,288 developers. It's quick & easy.

Better way to isolate string

Greetings.

Given the string s below and using only python built-in capabilities,
I am trying to isolate the substring G132153. This string may have any
number of digits but the pieces around it will not change. I have
accomplished this with split but there must be a more elegant and
compact way to do this.

>>s ='<a href="../active/Group_Detail.php?GroupID=G132153&SvcType=1&AType=V " class="dvLink">G132153</a>'
t = s.split('">')
u = t[-1].split('<')
v = u[0]
v
'G132153'
Thanks,

jvh

May 11 '07 #1
3 1201
I suppose a one liner would look better, but I am alway leery of these
things 'breaking'.

t = s.split('">')[-1].split('<')[0]
s ='<a href="../active/Group_Detail.php?
GroupID=G132153&SvcType=1&AType=V" class="dvLink">G132153</a>'

jh

May 11 '07 #2
HMS Surprise wrote:
I suppose a one liner would look better, but I am alway leery of these
things 'breaking'.

t = s.split('">')[-1].split('<')[0]
s ='<a href="../active/Group_Detail.php?
GroupID=G132153&SvcType=1&AType=V" class="dvLink">G132153</a>'
Only if you're competing in an obscurity competition ;)

If you're really confined to built-ins (ie you can't import
a single module) then just go with your original solution.
Why not?

If you can import modules, then you want to look
at the urlparser and cgi modules, I suspect.

TJG
May 11 '07 #3
On May 11, 10:45 am, Tim Golden <m...@timgolden.me.ukwrote:
HMS Surprise wrote:
I suppose a one liner would look better, but I am alway leery of these
things 'breaking'.
t = s.split('">')[-1].split('<')[0]
s ='<a href="../active/Group_Detail.php?
GroupID=G132153&SvcType=1&AType=V" class="dvLink">G132153</a>'

Only if you're competing in an obscurity competition ;)

If you're really confined to built-ins (ie you can't import
a single module) then just go with your original solution.
Why not?

If you can import modules, then you want to look
at the urlparser and cgi modules, I suspect.

TJG
Thanks for replying Tim. Good point.

jh

May 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Robert Zurer | last post: by
4 posts views Thread by Garibaldi | last post: by
4 posts views Thread by Jim Bradstreet | last post: by
22 posts views Thread by JoeC | last post: by
12 posts views Thread by garyusenet | last post: by
23 posts views Thread by mike3 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.