Regular expressions question
Jussi Salmela
tiedon_jano at hotmail.com
Tue Jan 16 10:34:10 EST 2007
Victor Polukcht kirjoitti:
> I have 2 strings:
>
> "Global etsi3 *200 ok 30 100% 100%
> Outgoing"
> and
> "Global etsi3 * 4 ok 30 100% 100%
> Outgoing"
>
> The difference is "*200" instead of "* 4". Is there ability to write a
> regular expression that will match both of that strings?
>
If the goal is not to study regular expressions, here's a solution
without them. Not so short, but working.
lst = [
"Global etsi3 *200 ok 30 100% 100%
Outgoing",
"Global etsi3 * 4 ok 30 100% 100%
Outgoing"]
for e in lst:
es = e.split()
if len(es) == 9:
num_val = es[3]
else:
num_val = es[2][1:]
print es[0], num_val, es[-3], es[-2]
Cheers,
Jussi
More information about the Python-list
mailing list