0

I need to find which portion of a starting string is inside another larger string.

This is an example:

string_1 = "smuAlarmNotification"
string_2 = "smuAlarmType: Enumeration of integer in interval [0...7] with enumerators"
sub = find_substring(string_2, string_1)

ouput = "smuAlarm"

Do you have any idea?

Thanks, Davide

  • So you want a function that gets the exact same parts of 2 string and puts them into another string. Can you post your attempt so far? – Josip Juros Feb 22 '22 at 13:09
  • 2
    I'd say, this lacks some details (and effort) - e.g. "ation" is also part of your first and second string. So, do you only want the largest match of the start of both strings, or the largetst match of the start of the first string (anywhere in the second string), or any (largest) match? Please describe the edge cases and show us what you've tried. – Mike Scotty Feb 22 '22 at 13:11
  • Can you be more precise? `string_1`'s substring `"s"` appears a bunch of times inside `string_2`. How large should the output be? What happens if there are duplicates? – jfaccioni Feb 22 '22 at 13:11
  • Sorry, I was not very precise. I need to find the largest possible substring match (no spaces or special characters). So in my example it would be "smuAlarm". If for example we have: string_1 = "Hello dears, my name is David" string_2 = "Daniel" the ouput should be: "Da" – Davide Tamagnini Feb 22 '22 at 13:19
  • https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Python – Cubix48 Feb 22 '22 at 13:31

0 Answers0