DEV Community

Kozo Oeda
Kozo Oeda

Posted on

Implementing auto-completion by Regex

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

Top comments (0)