[cs615asa] The Homework#N Report

Chenyi Zhang czhang42 at stevens.edu
Mon May 4 14:55:07 EDT 2015


#HW N
#CHENYI ZHANG
#APR - 31 - 2015

I went to the "A Gentle Introduction to Regular Expression in JavaScript"
event organized by NY Java-script group of "meetup.com" last Thursday. It
does not have a really deep description of Regular Expression. However, it
gave me some idea of why Regular Expression is important.

Regular Expression is a string which used to match specific strings in a
string. It makes string processing without human possible. Also it is easy
to extend the rule of process. The only problem with Regular Expression is
easy to write rather than read. Once the Regular Expression is going really
long, it is impossible that we can analysis that. However, for a strict
rule for a perfect match, the regular Expression will be some lines.

The presenter is a web developer. One of the duty is analysis most of the
data. Most data is not well formatted, like date, some times people will
write like "May - 21", "5-21", "21-5" and many other format. However, if I
wanna put them in our own database, it can not be like this. All things
must be set into same format. Most language like Java, Python they all
offer lots of methods for people to handle the Regular Expression.

By using Regular Expression, strings can be put into script for processing.
It will be really painful by using regular programming method to deal with
strings. Whenever we had a exception, we may had to rebuild all our code
again.

Also, I heard about the sentence that Software developers say most is "It
works on my machine." Well, I had to say.... It is.

Here is some notes from the meetup.

1. You still need to analysis the text before we can begin to use Regular
Expression.

2. It is differece between different encoding.

3. Different language may not share same gramma, check before using it.

Some Example:
 1. Match a ID from Youtube url:

url.match(/.+:\/\/.+\/.+v?=(\w+)/).pop()
the output will be "dQw4w9WgXcQ"

2. Using Regular Expression to match an Email address:

The official One:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
          |  "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
              |  \\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
        @
(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
          |  \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
               (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:
                  (?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
                  |  \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
             \])

Reference:
Event slides: http://moimikey.github.io/a-gentle-intro-to-regex/#/
github: https://github.com/moimikey/a-gentle-intro-to-regex
Slug Challenge: https://gist.github.com/jdaudier/743d2b56091e688702d8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.stevens.edu/mailman/private/cs615asa/attachments/20150504/93e7758e/attachment.html>


More information about the cs615asa mailing list