[cs615asa] The Homework#N Report

Xinghuan Qi xqi7 at stevens.edu
Tue Apr 28 15:49:50 EDT 2015


Hello,

I put my report for HW#N here:

I went to "A gentle Introduction to Regular Expression in JavaScript" which
is organized by NY-script group of "meet.up" last Thursday. As it's called,
it's an entry level meet up without deep description of Regular Expression.
The main purpose of this meet up is to give some idea of the importance of
Regular Expression and where should we use it.

Regular Expression is something that used to match or replace strings. Or
in another word, it used to extract information from some data that is not
well formatted. It's very useful for someone that working in Web
programming or system administration. Because we always need to get a
special data from a huge number of it. For instance, we may sometimes need
to get video ID (like AHtq3V7oKmU) from an url like:
https://youtube.com/watch?v=dQw4w9WgXcQ. It'll be easy to do with Regular
Expression.
We can get what we want by:

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

It'll be pretty complex if we process it char by char in a loop like
for(int i=0; i< url.size(); i++). I think we may need 50 or more lines to
finish. So Regular Expression is a simple and effective way to process
strings.

But there are some problems of Regular Expression. It's easy to write, but
pretty hard to read. Sometimes the Expression need many lines to put. Such
as the presenter shows in meet up(official standard RFC 5322, which is used
to match a E-mail address):

(?:[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])+)
             \])
It's impossible for others to read it. So the presenter gave an idea that
we should solute just one problem with one Regular Expression. We can put a
comment near the Expression we write, and for the next time we need it, we
can just read the comment and copy it.

Finally, the presenter gave us a challenge which is to process a article
with Regular Expression. It should be done by JavaScript, but I'm not
familiar with it. I try to do it by shell in Linux like what we did in
HW#3. But actually it's not easy as looked : )

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, a
challenge should be completed using regular expression if you have interest.

Regards,
Xinghuan Qi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs615asa/attachments/20150428/96c1df87/attachment.html>


More information about the cs615asa mailing list