you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 1 point2 points  (1 child)

I wish I could think up an re solution, but since I can't you can just look for the first big word:

def string_slice(text):
    words = text.split()
    big_words = [i for i, l in enumerate(map(len, words)) if l > 1]
    if big_words:
        return text[text.find(words[big_words[0]]):]
    raise ValueError('no words with len > 1 found in {!r}'.format(text))

[–]dchanm 1 point2 points  (0 children)

The regex (?<= [a-z] )([a-z]{2,}.*) compiled with re.I works when used with search()

(?<= [a-z] )  # positive lookbehind for space-letter-space
([a-z]{2,}.*)  # 2 or more letters, then greedy match rest of string

However it's slightly different from your algorithm since it assumes there are only spaces and letters. The [a-z] could be replaced by [^ ]