Better way to isolate string

H

HMS Surprise

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
 
H

HMS Surprise

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
 
T

Tim Golden

HMS said:
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
 
H

HMS Surprise

HMS said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top