By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

Better way to isolate string

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.