loading...

Implementing auto-completion by Regex

github logo ・1 min read

Using an input as a pattern(this is a reversed way of major use cases), you can implement a simple word auto-completion feature easily!

import re

example_words = ["Python", "Linux", "HHKB", "Pizza", "Ninja"]

pattern = input()

for word in example_words:
    if re.match(pattern, word, re.IGNORECASE):
        print(word)

Input example

li

Output

Linux

Version: Python 3

twitter logo DISCUSS
Classic DEV Post from May 31 '19

Presentation Tips for Technical Talks

Presentation Tips for Technical Talks

Kozo Oeda profile image
Writing codes in C++, Python and so on.

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️