Pattern Search Regular Expression

M

Mark Lawrence

I tend to reach for string methods rather than an RE so will something like
this suit you?

c:\Users\Mark\MyPython>type a.py
for s in ("In the ocean",
"On the ocean",
"By the ocean",
"In this group",
"In this group",
"By the new group"):
print(' '.join(s.split()[1:-1]))


c:\Users\Mark\MyPython>a
the
the
the
this
this
the new

Careful - " ".join(s.split()) != s

Eg:'s s'

It's pedantry, but true.

I'm sorry but I haven't the faintest idea what you're talking about. I
believe the code I posted works for the OP's needs. If it doesn't
please say so.

--
"Steve is going for the pink ball - and for those of you who are
watching in black and white, the pink is next to the green." Snooker
commentator 'Whispering' Ted Lowe.

Mark Lawrence
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top