hi
I'm new user of PYTHON and I want extract a little part into a string like this example

100|1999|pepito|False|27-10655374-1|False|||05/09/1952|1|4||3||1|1|8|67||4|False|True|False|oerirabtaa||||Femenino|0|0|0|0|0|0|2|

the part to extract (in the example, in black letter), have two parameters
1 is the part with exclusive format ##-########-#
2 ever is locate between 4º and 5º | symbol

thank's for your opinions
juanjo

Recommended Answers

All 4 Replies

I do not know if this filter is enough exclusive as I do not check the length of numbers but:

test= '100|1999|pepito|False|27-10655374-1|False|||05/09/1952|1|4||3||1|1|8|67||4|False|True|False|oerirabtaa||||Femenino|0|0|0|0|0|0|2|'
testlist = test.split('|')
for t in testlist:
    if t.translate(None,'0123456789')=='--': ## take out all numbers and compare
        print t

""" Output:
27-10655374-1
"""

tk's for all TONYJV!!!!!!!!!!!!!
I'll put your example on march now. But I use .split and find its work
see the example:

str = "100|1999|pepe|False|27-10651374-1|False|||05/09/1332|1|4||3||1|1|8|67||4|False|True|False|fdsfewía||||Femenino|0|0|0|0|0|0|2|";

print str.split('|')[4]; #this line print 5º item use | like separation symbol-Esta linea solo imprime el quinto item (arranca siempre en 0)

If you are sure the position is fixed in same place allways it is OK. I thought you said it must recognize by type of value format ##-########-#.

dear tonyjv
sorry but was my fault. I't tell you that importan point about the position. equal your example make me learn more nearest this wonderfull PYTHON. IS A POWERFULL PROGRAMMING LENGUAGE, REALY
TK'S so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.