Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background: Rust has a crate regex, which provides a library for parsing, compiling and executing regular expressions. See https://docs.rs/regex/latest/regex/ There are examples of using regular

Background:

Rust has a crate regex, which provides a library for parsing, compiling and executing regular expressions. See https://docs.rs/regex/latest/regex/

There are examples of using regular expressions in Rust available at https://docs.rs/regex/latest/regex/

There is a handy tool for testing Rust regular expressions at: https://rustexp.lpil.uk/ This tool can be used to test a regular expression before committing it to code.

Finally, there is a walk-through of a person implementing regular expressions in Rust located at: https://dev.to/carlyraejepsenstan/regular-expressions-in-rust-5c1c

You may use the examples as starting points for your program. Be sure to document properly and give credit where credit is due.

Process:

Create a Rust program(s) that uses regular expressions to (note this may be completed as a single program or as a series of programs):

Search text files looking for addresses. https://xkcd.com/208/

Make assumptions about what would define an address. Create a regular expression which searches text files for addresses based on your assumptions. Validate the functioning.

Search log files

Searching large log files for critical events is a common task in cybersecurity. One of the most efficient ways to do so is using regular expressions. These may be used in a quick script or built into a program for more robust long-term monitoring. Many network and systems monitoring tools provide access to regular expressions to search log files as well. While these tools also provide some level of simplified search capabilities, these have nowhere near the power of regular expressions.

For this section, create regular expressions to search log files of your choosing (network, web, server, etc.) to find at least 3 events of interest where the event of interest must have at least three indicators it is of interest (ex: event type, time-stamp value, event code, interesting text, parameter value, field value, etc.).

Demonstrate the ability of your program to extract the events of interest.

Find and consistently format all phone numbers (North American Numbering Plan - NANP and International).

For phones in the NANP, most numbers are 10 digits with 3 digits representing the area code, 3 the exchange code, and 4 the individual number. The first digit of the exchange code and the exchange code is 2-9. All other digits are 0-9. The NANP numbers are internationally recognized as a special county code of 1. Usually indicated as +1. The general format is +1 (NPA) NXX-XXXX. There are special 3-digit numbers of the form N11 (and 988). If a number is written with 10 digits, it is assumed to be a full number. If 7 digits, it is assumed to be only NXX-XXXX within the local area code. (Note: the example in the Rust Cookbook handles 10-digit numbers only).

In the rest of the world, phone numbers can be any length. They are in the format +CC AA XXXX where CC is the country code, which can vary from 1 to 3 digits, AA is the area, city, or region code, where the length can be from 1 to 8 digits, and XXX is the subscriber number, which can vary from 2 to 10 digits. The total number of digits may not be more than 15 including country, area, and exchange. The numbers can be written with 00 in place of the plus sign in front of the country code, or just the country code. For example +46 is Sweden. It could be written as 46, 0046, or 0146. Almost always, a space follows the country code. When written without the country code, numbers are usually written (and dialed) with a 0 before the area, city, region code. Most often when written, there is a space between this code and the number. However, there may also be a dash, -, or no space. If there is no indicator, then determining where the code splits is different for each country. Make an assumption that the first code is 3 digits and format based on that. In some countries, the subscriber number is written in pairs with spaces in between. In some other countries, there may be both an area and city code. In Australia for example: +61 3 7010 4321.

A typical phone number in England would be +44 66 332251, in Sweden +46 18 32 97 54. Those numbers locally would be written and dialed as 06655 332241 and 018 32 97 54. In some countries the preferred writing of internal numbers is similar to in the NANP. The numbers may be written as (06655) 332241 or (018) 32 97 54. They are also sometimes seen in the form 06655-332241 or 018-32 97 54.

There are also some 3-digit emergency or special numbers (112, 999) the use of which varies by country.

Your parser should recognize all 10-digit numbers that do not start with a +, or 00 as NANP numbers, as well as numbers that start with +1. It should recognize 7-digit numbers which do not start with a country code indicator, or a 0, as local NANP numbers. It should recognize the NANP and International 3-digit numbers. It should consider all other numbers to be international numbers either in format which includes the country code, or a local only format.

Obviously, there are more quirks to the formatting, but for this exercise, this is sufficient. If you do want to explore the details, refer to E.164 https://www.itu.int/rec/T-REC-E.164/ and E.123 https://www.itu.int/rec/T-REC-E.123 as well as the specific local guidelines from the countries you are interested in.

Demonstrate the ability of your expression to find and format phone numbers appropriately.

(Extra credit) Demonstrate another non-trivial implementation of regular expressions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago