JavaScript Regular Expressions
Learning RegExp ...
JavaScript has some amazingly powerful features that are comparable with many advanced programming languages and one such feature is regular expressions (RegExp for short). The problem is that to many, they are considered a 'black art' and because of this, they are usually only understood by an elite few with programming experience.
This page employs a novel method of teaching regular expressions that is is designed to enable web authors who do not have programming experience, to start using regular expressions in their own JavaScript scripts and in the process, gain an understanding of how regular expressions work.
JavaScript Implimentation ...
Regular expressions employ a system of pattern matching that is exactly the same across a variety of advanced programming languages, the only difference being the different ways they are implimented. In JavaScript for example, the keyword that identifies them is 'RegExp' and they are only supported in four of JavaScript's String Methods. Also, you cannot replace a regular expression pattern with another regular expression pattern, only with a string. A regular expression object contains the pattern of a regular expression. It has properties and methods for using that regular expression to find and replace matches in strings or to match patterns in strings. JavaScript RegExp can be used in the following JavaScript String Methods.
- string.match()
- string.search()
- string.replace()
- string.split()
Some Basic Examples ...
string = string.replace(new RegExp(/\s+$/),""); // END
A More Complex Example ...
This example uses a JavaScript subroutine that contains eleven regular expression matches or replacements. The job of the subroutine is to determine if a URL contains a sub-domain but this apparently simple task is actually quite a complex task to achieve. The advantage of using this example is that it enables us to demonstrate a wide range of regular expressions and you can 'cherry pick' the usages for use in your own scripts.
url = url.replace(new RegExp(/^\s+/),""); // START
url = url.replace(new RegExp(/\s+$/),""); // END
url = url.replace(new RegExp(/\\/g),"/");
url = url.replace(new RegExp(/^http\:\/\/|^https\:\/\/|^ftp\:\/\//i),"");
var subDomain = (url.match(new RegExp(/\./g))) ? true : false;
Link Directly To This Page ...
help support free information on the Internet ...
Many users prefer to link directly to individual content pages on Web-Wise-Wizard. If you would like to do this then we have provided the following HTML/CSS link script which you can copy and paste directly into your HTML editor. Alternatively, you might like to use our New Dynamic Link Generator to create a link that more fully meets your own particular requirements.
the link displayed ...
select/copy the link Markup ...


