MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
ans =

'Janice 529-882-1759 Fresno, CA [email protected]'

Step 1 — Identify Unique Patterns in the Text

A typical email address is made up of standard components: the user's account name,
followed by an @ sign, the name of the user's internet service provider (ISP), a dot
(period), and the domain to which the ISP belongs. The table below lists these
components in the left column, and generalizes the format of each component in the right
column.

Unique patterns of an email address General description of each pattern
Start with the account name
jan_stephens...

One or more lowercase letters and underscores

Add '@'
jan_stephens@...

@ sign

Add the ISP
jan_stephens@horizon...

One or more lowercase letters, no underscores

Add a dot (period)
jan_stephens@horizon....

Dot (period) character

Finish with the domain
[email protected]

com or net

Step 2 — Express Each Pattern as a Regular Expression

In this step, you translate the general formats derived in Step 1 into segments of a
regular expression. You then add these segments together to form the entire expression.

The table below shows the generalized format descriptions of each character pattern in
the left-most column. (This was carried forward from the right column of the table in Step
1.) The second column shows the operators or metacharacters that represent the
character pattern.

Description of each segment Pattern
One or more lowercase letters and underscores [a-z_]+
@ sign @
One or more lowercase letters, no underscores [a-z]+

2 Program Components

Free download pdf