How Do You Do a regex Operation in Python without Importing a Module?

Problem scenario
You need a pattern matching function in a Python program, but you cannot use "import re". What should you do?

Possible Solution #1
Use the index() function.

Here is an example:

foobar = "abcdefghijklmnopqrstuvwxyz"
print(foobar.index('jk'))

Possible Solution #2
Use the .starswith() function.

foobar = "abcdefghijklmnopqrstuvwxyz"
print(foobar.startswith('abc'))

Possible Solution #3
Use the find() function.

foobar = "abcdefghijklmnopqrstuvwxyz"
print(foobar.find('z'))

Leave a comment

Your email address will not be published. Required fields are marked *