-1

I'm looking for a function in python that works exactly like '%' does in SQL for matching strings. I need this to match some strings that have weird spacing due to the way they were exported so I'll need to put % in between every single word to find the strings that I want.

example:

"Hello how are you"

"Hello how are you"

"Hello how are you"

" Hello how are you"

I would like to use the sql way of matching strings to "%Hello%how%are%you%"

mikehuuuu
  • 111
  • 1
  • 1
  • 6

1 Answers1

0

Please explain more, But i think you mean this :

def re_string(your_string):

    renew_string = your_string.split(' ')

    buffer_result = []
    for words in renew_string:
        if words.replace(' ', '') == '':
            pass
        else:
            buffer_result.append(words)

    last_data = '%'.join(buffer_result)
    return last_data


print(re_string("Hello how are you"))
print(re_string(" Hello how are you"))
print(re_string(" Hello    how are          you"))
print(re_string("  Hello   how   are you "))

OUTPUT :

>> Hello%how%are%you
>> Hello%how%are%you
>> Hello%how%are%you
>> Hello%how%are%you
DRPK
  • 2,023
  • 1
  • 14
  • 27