Link Search Menu Expand Document

Module 3: Realtime Use Case of Regular Expressions for Beginners - Part 4

Previous Tutorial

You might be wondering by knowing that you can also use regex for address matching, though there is a wide variance in address content and formatting, still, you can use regex to match it to some extent.

Before we write the regex, let's try to understand this sample address format. Here the first set consists of street number and street name, followed by a comma. There is a city name followed by a comma and then there is a state name abbreviation like in our case TX stands for Texas. Lastly, there is a zip code. Once you identify the pattern, it becomes easy to write the regex.

Regular Expressions Use Case Realtime

Now let's jump into the demo to write the regex for matching this home address. In the input text, I have added some sample addresses. First, write the expression to match the street number and street name slash w and complete the group. This backslash w is not matching space. Add space and comma in the character class. Repeat this group one or more times by adding plus signs. We can also match this city name using this same expression. Add this expression again into one group by adding parenthesis and repeat this expression two times.

Now write the regex expression to match this state abbreviation. The state abbreviation is always consisting of two characters. For that define one group and in the character, the class adds the range. Then repeated it two times, followed by comma and space. The last one is a zip code. For that, use backslash d in one group and repeat it one or more times and assert the end of the string. This is how we can create the working regex to match the address.

Now use this same regex in the PDF multi-tool to find the address in the PDF file. In the PDF multi-tool, I have loaded one sample PDF file which contains the address over here. Click on this link and copy our regular expression, which we have just created. When I click on this find button, now it is highlighting the matching address. Our created regular expression is correct. Let's move to the next demo.

Regular Expressions Use Cases Realtime

Email address validation using regular expression is one of the most common tasks which may be required in any application which seeks email address as required information in the registration step or there may be more use cases. I think no need to explain the format of the email address as we all have our email addresses.

Let's jump into the demo to match the email address. Here I have added some sample email addresses in the input text. First, write a regex expression to match the user name or write the expression to match the character before the @ part. This username portion is consisting of capital A to capital Z. Define the character class and write the range over here and then digit. There can be an underscore or a dot or a hyphen. Repeat this character one or more times by adding plus sign characters over here. Add the @ character sign over here. After this, @ sign, there is a domain name.

For domain names, we need to write expressions, character class, and define the range in the character class. Copy it over here. In the domain name, there can be either dot or hyphen and same way repeat this character one or more times by adding plus sign character over here and add the DOT. Now to match the last part there can be either minimum of two characters and a maximum of four characters. For example(.com, .edu, .in etc). For that use this expression again in the character class. Define the range and limit the length to 2 to 4.

This is the working regex to match the email address. Find the email address in a PDF file using this same regex that we have created but in PDF multi-tool. In the PDF multi-tool, I have added one sample PDF file which contains the email address over here. Click on this link, which opens the pop-up, and copy our regular expression in these textbooks. When I click on the find next button, it is highlighting the valid email address. Another email address is also over here. This is how we can use our regex to find the valid email address in this tool.

Regular Expressions Use Case for Beginners

We have reached the end of the module. I hope you will take the time to work through the demos for yourself. So you can see how all of this works. I hope you enjoy this course. Feel free to improve the regex we learned in the demo over here.

Web API for developers Free Trial Offline SDK

Here's RegEx video tutorial:

Other useful articles:

Back to top

© , — All Rights Reserved - Terms of Use - Privacy Policy