Open Source For You — December 2017

(Steven Felgate) #1
http://www.OpenSourceForU.com | OPEN SOURCE FOR YOU | DECEMBER 2017 | 73

Insight Developers

I


n the previous issue of OSFY, we tackled pattern matching
in PHP using regular expressions. PHP is most often used
as a server-side scripting language but what if your client
doesn’t want to bother the server with all the work? Well,
then you have to process regular expressions at the client side
with JavaScript, which is almost synonymous with client-side
scripting language. So, in this article, we’ll discuss regular
expressions in JavaScript.
Though, technically, JavaScript is a general-purpose
programming language, it is often used as a client-side
scripting language to create interactive Web pages. With
the help of JavaScript runtime environments like Node.js,
JavaScript can also be used at the server-side. However, in
this article, we will discuss only the client-side scripting
aspects of JavaScript because we have already discussed
regular expressions in the server-side scripting language—
PHP. Just like we found out about PHP in the previous article
in this series, you will mostly see JavaScript code embedded
inside HTML script. As mentioned earlier in the series,
limited knowledge of HTML syntax will in no way affect the
understanding of the regular expressions used in JavaScript.

Each programming language has its own way of parsing regular expressions. We have
looked at how regular expressions work with different languages in the earlier four articles
in this series. Now we explore regular expressions in JavaScript.

Though we are mostly interested in the use of regular
expressions, as always, let’s begin with a brief discussion on
the syntax and history of JavaScript.
JavaScript is an interpreted programming language.
ECMAScript is a scripting language specification from the
European Computer Manufacturer’s Association (ECMA)
and International Organization for Standardization (ISO),
standardised in ECMA-262 and ISO/IEC 16262 for
JavaScript. JavaScript was introduced by Netscape Navigator
(now defunct) in 1995; soon Microsoft followed with its own
version of JavaScript which was officially named JScript.
The first edition of ECMAScript was released in June 1997
in an effort to settle the disputes between Netscape and
Microsoft regarding the standardisation of JavaScript. The
latest edition of ECMAScript, version 8, was released in June


  1. All modern Web browsers support JavaScript with the
    help of a JavaScript engine that is based on the ECMAScript
    specification. Chrome V8, often known as V8, is an open
    source JavaScript engine developed by Google for the
    Chrome browser. Even though JavaScript has borrowed a lot
    of syntax from Java, do remember that JavaScript is not Java.


Regular Expressions in Programming


Languages: The JavaScript Story

Free download pdf