Tuesday, November 4, 2014

JavaScript Methods for Pattern Matching

returned valueString methods
position|-1string.search(regexp)
new_stringstring.replace(regexp, replacement_str)
array|nullstring.match(regexp)
arraystring.split(regexp)
returned valueRegExp methods
array|nullregexp.exec(string)
booleanregexp.test(string)

JavaScript Regular Expression

1. Defining Regular Expressions in JavaScript

In JavaScript, regular expressions are represented by RegExp objects. RegExp objects may be created with the RegExp() constructor or with a literal syntax. Regular expression literals are specified as characters within a pair of slash characters.
For example:
var regexp = /^Hello JavaScript$/;
This regular expression could have equivalently been defined with the RegExp() constructor like this:
var regexp = new RegExp('^Hello JavaScript$');

Advanced Regular Expression Features


If you want to employ all regular expressions constructs and features you can't make it with a simple shell command or a tool, but you need to use a programming language. I use Perl, because it has the best and longest established support for regular expression.

Parenthesized Subexpressions

Earlier, we saw that regex engines support metacharacters \1, \2, \3, etc. to refer to the text matched by parenthesized subexpressions. Perl and most other modern regex-endowed languages also provide a way to refer to the text matched by parenthesized subexpressions from code outside of the regular expression, after a match has been successfully completed.

Saturday, November 1, 2014

Introduction to Perl

This guide introduces the Perl language through a number of sample programs. The aim of this guide is to understand how to use regular expressions with Perl.

1 - What is Perl Language

Perl is a scripting language suitable for web-processing. Perl was developed deriving its concepts of text handling and regular expression from two specialized languages called awk and sed.