0

I have a text and want to search few words in the text. For example the text in the form of string is:

this is a sample string...

and the word which I want to search is something like: sample.json so the sample should match in the string partially. And the output should be sample. I am using in and any to match the strings but these condition don't work.

       if any(word.startswith(text.lower())):
       # do something

also tried this condition:

if word.lower() in text.lower():
        # do something

Any hints? Thanks in advance.

badar
  • 55
  • 5
  • What exactly have you tried so far? We're much more here to help with specific questions of the form "I tried X, but it did not do what I expect and instead resulted in an error!" accompanied by a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – ti7 Jul 26 '22 at 21:01
  • 2
    You should look for the algorithm of Longest common substring – Sergio Peñafiel Jul 26 '22 at 21:02
  • thanks for the hint. Code is also given on this link: https://linuxhint.com/find-longest-common-substring-python/ – badar Jul 26 '22 at 21:26

0 Answers0