Find one word for a sentence

So, I am trying to find a word (a complete word) in a sentence. Lets say the sentence is

Str1 = "1. how are you doing"

and that I am interested in finding if

Str2 = "1."

is in it. If I do,

re.search(r"%sb" % Str2, Str1, re.IGNORECASE)

it should say that a match was found, isn’t it? but the re.search fails for this query. why?

Martijn Pieters's user avatar

asked Oct 29, 2013 at 14:21

suzee's user avatar

There are two things wrong here:

  1. b matches a position between a word and a non-word character, so between any letter, digit or underscore, and a character that doesn’t match that set.

    You are trying to match the boundary between a . and a space; both are non-word characters and the b anchor would never match there.

  2. You are handing re a 1., which means ‘match a 1 and any other character’. You’d need to escape the dot by using re.escape() to match a literal ..

The following works better:

re.search(r"%s(?:s|$)" % re.escape(Str2), Str1, re.IGNORECASE)

Now it’ll match your input literally, and look for a following space or the end of the string. The (?:...) creates a non-capturing group (always a good idea unless you specifically need to capture sections of the match); inside the group there is a | pipe to give two alternatives; either match s (whitespace) or match $ (end of a line). You can expand this as needed.

Demo:

>>> import re
>>> Str1 = "1. how are you doing"
>>> Str2 = "1."
>>> re.search(r"%s(?:s|$)" % re.escape(Str2), Str1, re.IGNORECASE)
<_sre.SRE_Match object at 0x10457eed0>
>>> _.group(0)
'1. '

Community's user avatar

answered Oct 29, 2013 at 14:26

Martijn Pieters's user avatar

Martijn PietersMartijn Pieters

1.0m288 gold badges4004 silver badges3309 bronze badges

4

Change,
lump,
drowned, occupy, straight

  1. Glaciers
    provide vital evidence of climate …

What you need is not pills but
a simple … of scene.

If you need money, there’s
some spare … in my coat pocket.

2. Grassland and savannah …
a substantial part of Southern Africa.

It’s a long journey — let’s
take some books to … the children.

The protesting students intend
to … the Holman Building.

3. The vet said the … on the
dog’s face was not cancerous.

She had a … in her throat
and a tear in her eye when she said goodbye.

Get up and do some work, you
lazy …

4. Many of the wildebeest
didn’t make it and … half-way across the river.

My voice was … out by the
sound of builders drilling.

I … my meal in sauce to hide
the bitter taste.

5. The falconer trained the
hawk to fly in a perfectly … line.

So let’s get this … ; you
say you saw the man break in through the window.

Why can’t you just give me a …
answer for once in your life?

31. Comment on the change of meanings in the italicized words.

1. They sat
on the rug before the fireplace, watching the rising tongues
of flame
.
2. He inspired universal confidence and had an
iron nerve
.
3. He was burning
with a desire

to meet his old friends. 4. As I spoke, rage
sparkled

in my eyes. 5. Emotion squeezed
Soames’ heart. 6. Here was the great mysterious city which was still
a
magnet

for her. 7. Carrie’s anger melted
on the instant. 8. Some books are to
be tasted
,
others swallowed,
and some few to
be chewed
and
digested.

32. Define the meanings of the italicized words in the following sentences.

1. I began
to search the flat, looking in drawers and boxes to see if I could
find a
key
.
I tumbled with a sort of splash upon the
keys

of a piano. Now the orchestra is playing yellow cocktail music and
the opera of voices pitches a
key
higher.

2. I sat
down with my
head

in my hands, until I heard the phone taken up inside and the butler’s
voice calling a taxi. G.Quarterman possessed more power than many
heads
of the state.

3. I walked
into Hyde Park, fell
flat upon the grass and almost immediately fell
asleep.

4. Her
mouth

opened crookedly half an inch, and she shot a few words at one like
pebbles. Would you like me to come to the
mouth

of the river with you? I put the letter into the
mouth

of the box and let it go.

Homonyms Homographs

33. How would you pronounce each of the underlined words in the sentences below? Chose a word with a similar sound from the brackets.

1.
The girl I live
with knows a good pub with live
music. (dive/give)

2.
The main house
houses
a collection of rare stamps. (mouse/rouse)

3.
They bathed
the children after they had bathed
in the sea. (lathe/path)

4.
You sow
the seeds while I feed the sow.
(cow/glow)

5.
The violinist in the bow
tie took a bow.
(allow/flow)

6.
He’s the lead
singer in the group ‘Lead
piping’. (head/deed)

7.
What a row
from the last house in the row!
(plough/though)

8.
Does he still suffer from his war wound?
(found/mooned)

9.
I wound
the rope around the tree to strengthen it against the gale.
(round/tuned)

10.
It’s quite hard to wind
in the sails in this wind.
(find/tinned)

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]

  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #

Cloudy-aw


  • #1

Hello friends,

I need your help with the following problem.
There are three sentences, with a gap in each of them.
I need to find the one single word (and only one) which can fill all the three gaps and fit properly.

1. I’m sure Maria will ………. for the beach as soon as she’ll be unpacked.

2. How do you think Frizt will …….. each month, with his new job ?

3. He’s achieving great results, I’m sure the management will ……. him sales manager next year.

I couldn’t find anything better than «head», but I’m pretty sure it’s wrong.
A guy who was at the exam with me tried «drive», which is also wrong.
Any suggestions ?

Ciao
Claudio

  • la grive solitaire


    • #2

    Hi Claudio,

    Is there a word missing from the second sentence?

    • #3

    Cloudy-aw said:

    Hello friends,

    1. I’m sure Maria will ………. for the beach as soon as she’ll be unpacked.

    Can future tense be after as soon as?
    If my memories serve me right, my teacher said never.

    la grive solitaire


    • #4

    You’re right, Erik.:) It should read:

    1. I’m sure Maria will …….. for the beach as soon as she’s [she has] unpacked.

    Neever


    • #5

    Hi Claudio,

    I can’t find a word that does all three, but I have to say, sentences 1 and 2 sound wrong regardless. «as soon as she’ll be unpacked» is ungrammatical, like you said, and «each month, with his new job ?» seems to have a misplaced comma, and at first glance «with» is incorrect too. «In» would work better, as long as the missing word doesn’t change the structure. Mind you, my observation still doesn’t help much! Sorry!

    la grive solitaire


    • #6

    I think the missing word for all three is «make»:

    …she’ll make for the beach

    How much will Fritz make each month

    …management will make him sales manager…

    • #7

    Cloudy-aw said:

    Hello friends,

    I need your help with the following problem.
    There are three sentences, with a gap in each of them.
    I need to find the one single word (and only one) which can fill all the three gaps and fit properly.

    1. I’m sure Maria will ………. for the beach as soon as

    she’ll be

    she has unpacked.

    2. How do you think Frizt will …….. each month, with his new job ?

    3. He’s achieving great results, I’m sure the management will ……. him sales manager next year.

    I couldn’t find anything better than «head», but I’m pretty sure it’s wrong.
    A guy who was at the exam with me tried «drive», which is also wrong.
    Any suggestions ?

    Ciao
    Claudio

    Hello Claudio,

    The obvious answer, to me, is «make». But, as La Grive says, there seems to be something missing in the second sentence. That would need the addition of «out» — «How do you think Fritz will make out each month . . . ?»

    Regards,
    LRV

    Joelline


    • #8

    Cloudy-aw said:

    1. I’m sure Maria will MAKE for the beach as soon as she HAS unpacked.

    2. How MUCH do you think Frizt will MAKE each month, with his new job ?

    3. He’s achieving great results, I’m sure the management will MAKE him sales manager next year.

    Claudio

    Omitted words and other errors MAKE this difficult to correct!

    Cloudy-aw


    • #9

    Thank you for your kind and prompt replies.

    At the exam I couldn’t take note of the sentences, therefore I obviously stuffed them with errors when I tried (with the only help of my memory) to type them in the first post of this thread.

    Anyway you all agree that the word is «make».
    I have another question : is «make for the beach» a bit colloquial ? I ask because I have never seen such a form. Is it BE ? Or AE ?

    Ciao and thank you again
    Claudio

    • #10

    In BE I say «head for the beach».

    Regards,
    LRV

    • #11

    I agree with Joelline. Even without the mistakes, it is very difficult. I´d guess that «make for» is both BE and AE, though I´ll let the Americams speak for themselves. It´s certainly BE, though a bit unusual, perhaps more written than spoken?

    • #12

    In AE I have heard and understand «make for the beach,» although its not the primary way of saying it. We usually say «head to the beach» or «go to the beach.» I am sure there are other but thats all I can think of at the moment.

    panjandrum


    • #13

    Let me offer sincere sympathy and suggest that you reserve the right to appeal to the European Court of Human Rights. This is cruel and unusual punishment, not a legitimate examination in the use of English.

    I’ll accept that it is possible to use make in each of these sentences. But I stress possible and assert that it is unnatural.

    • #14

    These are questions that come out in FCE, CAE and CPE.

    Here are my attempts:

    1. head

    2. fare

    3. name

    Joelline


    • #15

    Ooops, Cracker Jack,

    Go back and read the nasty directions again. That was our problem: you had to use the 1 word (the same word) in all 3 sentences!

    It is for this reason that the Europeans here will be appealing to the European Court of Human Rights, and the Americans will be appealing to the Supreme Court! This was, indeed, cruel and unusual punishment!

    Best,
    Joelline

    coconutpalm


    • #16

    If the second sentence is «How much do you think he will make each month, with his new job?», is «make» the correct word then?

    Joelline


    • #17

    Hi coconut palm,

    Yes, and that’s what I changed it to in post #8.

    Joelline

    coconutpalm


    • #18

    Oh, I’m sorry that I didn’t notice the quote!
    I promise I will pay more attention next time!
    Thank you, Joelline, for confirming my assumption!

    • #19

    Joelline said:

    Ooops, Cracker Jack,

    Go back and read the nasty directions again. That was our problem: you had to use the 1 word (the same word) in all 3 sentences!

    It is for this reason that the Europeans here will be appealing to the European Court of Human Rights, and the Americans will be appealing to the Supreme Court! This was, indeed, cruel and unusual punishment!

    Best,
    Joelline

    Oh gee!!! Thanks for reminding me Joelline. That was very careless of me. Well, you have all the right to deplore those bastard-examiners. Not just cruel and usual. It is stupid. Go ahead.

    cuchuflete


    • #20

    «Make for» meaning to go to, or head in the direction of, is not
    used with any frequency in AE. It’s found quite a bit in 19th and early 20th century writing, but has fallen out of favor in recent decades.

    Cloudy-aw


    • #21

    cuchuflete said:

    «Make for» meaning to go to, or head in the direction of, is not
    used with any frequency in AE. It’s found quite a bit in 19th and early 20th century writing, but has fallen out of favor in recent decades.

    Except for occasional appearances, one of them being the written part of the CPE exam I tried last week…
    I agree with Cracker Jack’s opinion, although my view is not so mild.

    Ciao
    Claudio

    • #22

    My understanding is that Cambridge questions are tested and a sufficient number of ‘guinea pigs’ must have answered the question for it to have been shown to help in grading candidates’ English ability.

    I don’t feel «make for the beach» is so unusual.

    Joelline


    • #23

    It’s not unusual if you’re reciting dialogue in a WW II movie about the beaches at Normandy! Otherwise, when is the last time you said it or heard someone say it?

    DictionaryThey call them dictionarys… dry www.dictionary.com where you can type a definition and find the word that best matches ;)

    great technology we have ay… wow… dictionarys

    DictionaryThey call them dictionarys… dry www.dictionary.com where you can type a definition and find the word that best matches ;)

    great technology we have ay… wow… dictionarys

    DictionaryThey call them dictionarys… try www.dictionary.com where you can type a definition and find the word that best matches ;)

    great technology we have ay… wow… dictionarys

    Dude, you’re stupid . . . . they’re asking for a place where you type a word and it gives you a sentence with it you big DUMBO . . . . . . Oh and by the way, you spelled dictionaries wrong!

    Nguyễn Thị Ngọc Thơ Key đây nha :

    Find one word only which fits in all three sentences :

    1,

    A. I’d like to know what lay behind my father’s decision to change his will

    lie behind sth : là lời giải đáp cho cái gì, là nguyên nhân của cái gì

    B. People think that this company is trying to hide behind these reports

    hide behind : che dấu một thứ gì đó không được tốt đẹp cho lắm

    C. My sister promises to stand behind me no matter what I want to do

    stand behind someone : ủng hộ ai đó

    2,

    A. My cousins live off my grandparents

    live off : dựa vào thứ gì đó hoặc thứ gì đó là nguồn hỗ trợ hoặc thu nhập

    B. The factory had to cut back production and lay off workers

    lay off someone : đuổi việc, sa thải ai

    C. The robbers made off with a large amount of money

    make off : bỏ đi nhanh chóng

    3,

    A. She used to butter up her boss to get a new job position

    butter up = flatter : nịnh nọt

    B. If I don’t finish the report tomorrow, I will be up the creek

    up the creek : tobe in serious trouble

    C. I’ve been very tired all day. I need to loosen up

    loosen up = relax

    4,

    A. You must chew it over first. I need your decision now

    Chew something over / Chew over something : Suy nghĩ về việc gì đó một cách cẩn thận, bàn bạc nó với người khác trước khi quyết định làm cái gì

    B. Jack’s mother said that she would talk it over with Jack’s father.

    talk it over : thảo luận về việc gì đó

    C. While he told us that joke, I was doubled over with laughter

    be doubled over : bị gập người xuống vì đang bị đau hoặc đang cười

    Like this post? Please share to your friends:
  • Find odd word which is not used with do
  • Find number in excel row
  • Find not finding in excel
  • Find not empty cells excel
  • Find not a number in excel