Introduction
In this semester, I and several classmates studied self-directed study course under the supervision of professor Max Troyer. The name of the course is Localization Engineering. We aimed to explore basic skills a localization engineer needs to have and spent most of our time on regular expression. Regular expression is a powerful tool that can help engineers extract the information needed as well as breaking down texts and organizing them in whatever ways they like. As a localization engineer, one need to be familiar with all “tricks” that associate with texts of documents in various formats. Therefore, regular expression is a required skill for us who want to be qualified localization engineers.
This project is a python script that runs on the command prompt. It is a contact form that stores contact information, such as name, email, and phone number. One can search information by typing the name of the contact person and update contact information if it does not exist in the contact form.
Regular expression serves as the most important component in this program. Without further ado, I will break down the program in details in the following article.
Extract information
The following picture presents what things this program can do.

We can simply type the name of the contact person to get corresponding contact information. Apparently, the program has contact information pre-stored. So, what will happen if we type a contact person who doesn’t exist in the contact form?

We can see from the above picture that the program would ask people to update contact information when the contact person does not exist in the contact form. After typing all relevant information, we can search the name again, and get the contact information we just updated.
This contact form is built based on regular expression. The first step is to extract information we need in the “database”.

You may be surprise when seeing our “database” of the program. Yup, it’s actually a simple plain text with basic contact information. We don’t need it being organized since we will employ regular expressions to extract the information we need.

First of all, we need to open our “database” and read the content of it as an object. Then I wrote three regular expressions to extract information in three categories — name, email and phone number.

Next, I created three empty lists and put information I just got into them according to their categories. Now, I have already had all information ready for future use.
Create dictionaries
The key of this program is to have a search function when typing the name of the contact person. Python gets a powerful dictionary feature that could help us achieve this goal.
Dictionary, the equivalent of hashmap in Java, could grant users several useful methods. Search is one of them. Here is an example of python dictionary:
{‘color’: ‘pink’, ‘food’: ‘Spam’, ‘quantity’: 5}
Color, food and quantity serves as “name”. You can get values by searching these names. It’s basically like key and value pairs in property files.
Let us get back to our program. We have already saved information of three categories into three separate lists. So, we have name list, email list and phone list. Thinking of our program and what goals we want to attain, we need to create dictionary to obtain search function, and we need to have email and phone number attached to the name separately. One dictionary could not help us achieve the above goals. In addition, the dictionary does not allow to have the name repeated twice in it. Under this circumstance, I concluded that I need two separate dictionaries to complete the task.

I used the zip function to combine name list with phone list and email list separately, and made them into two dictionaries by employing dict function.

The above picture shows the main loop of our program. In the first scenario, if the name we type existed in both dictionaries, we could print corresponding values according to the name. In the second scenario, since name is an input before the if condition, it’s already written into two dictionaries. Therefore, we could write phone and email values into two dictionaries based on that. By now, you can see how powerful python dictionary is.
Update file
Dictionary can only store information temporarily. So, we need to save updated information into our plain text “database”. The codes in the following picture helps us attain this goal.

For the purpose of testing whether the method is successful, I closed the program and re-opened it. I typed the name “Roin”, and I got the following result.

Yeah! My method works. I successfully saved updated contact information into the database.
Lastly, let’s look at our database one more time.

Our database is turned into python dictionary form after running the program! It’s totally different from the initial database.
Conclusion
A few words I would like to talk about before finishing this article is about the “pyperclip” version of this program. In short, in addition to open the file to read the content of the database, we can also copy the content into the clipboard, and achieve similar result when running the program. The only difference is to import the python pyperclip package beforehand. One can use these two versions based on their preferences and different needs.
Regular expression can be applied not only in contact form but also in many other occasions. As a localization track student, I would like to explore more use of it in future attempts.