python - Check for letter after a substring -


i'm trying find way check letter after sub-string. have searched both on internet , google. if sub-string is: sub, , text is: substrings cool, should return true , if text is: sub dafdgnjgf should return false.

if you're looking any valid letter after given sub-string, can first find position of sub-string inside string str.find, check if index after sub-string matches ascii_letters string:

from string import ascii_letters  sub = 'sub' s = 'substrings cool' 

now, check can this, index string after @ position str.find(sub) + len(sub) i.e position after sub-string:

if s[s.find(sub) + len(sub)] in ascii_letters:     print(true) else:     print(false) 

this prints true if sub followed letter, if not:

s = 'sub dafdgnjgf' 

it prints false.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -