Python student seeks help regex/strings

P

Petyr David

I'm familiar with simple string substitutions in shell and perl:

string= "I have 30 days to find it"

echo $string | sed "s/\(.*\)\(30\)\(.*\)/\2/

which will (if I did it right) leave 30

and perl likewise.

I'm having trouble figuring out how to do this in Python and it's not
for lack of trying to find an example. It can't be this hard is it?

Hopefully I will limit my newbie questions.

Thanks

Peter
 
J

John Machin

I'm familiar with simple string substitutions in shell and perl:

string= "I have 30 days to find it"

echo $string | sed "s/\(.*\)\(30\)\(.*\)/\2/

which will (if I did it right) leave 30

and perl likewise.

I'm having trouble figuring out how to do this in Python and it's not
for lack of trying to find an example. It can't be this hard is it?

No, it isn't; there are examples in the docs (http://docs.python.org/
library/re.html#re.sub) and the HOWTO (http://docs.python.org/dev/
howto/regex.html#search-and-replace) ... how did you manage to avoid
finding them?
'30'
 

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
474,293
Messages
2,571,502
Members
48,189
Latest member
StaciLgf76

Latest Threads

Top