How to extract a couple marked strings from a line (python)

Posted by GoJian on Stack Overflow See other posts from Stack Overflow or by GoJian
Published on 2010-04-04T05:47:50Z Indexed on 2010/04/04 5:53 UTC
Read the original article Hit count: 230

Filed under:
|
|
|

My Friends,

I spent quite some time on this one... but cannot yet figure out a better way to do it. I am coding in python, by the way.

So, here is a line of text in a file I am working with, for example:

">ref|ZP_01631227.1| 3-dehydroquinate synthase [Nodularia spumigena CCY9414]..."

How can I extract the two strings "ZP_01631227.1" and "Nodularia spumigena CCY9414" from the line?

The pairs of "| |" and brackets are like markers so we know we want to get the strings in between the two...

I guess I can probably loop over all the characters in the line and do it the hard way. It just takes so much time... Wondering if there is a python library or other smart ways to do it nicely?

Thanks to all!

© Stack Overflow or respective owner

Related posts about python

Related posts about string