Monday, August 16, 2010

Using Regular Expressions

I had to re-learn (again) reg Exp so thought I would write it down :-)

The idea here is to search for a bit of text in antother:

The /gi option means global and case insensitive

var pattern = //gi
var match = stringToSearch.search( pattern )

If match > -1 a match has been found.

for example:
var stringToSearch = "Is Rob here"
var pattern = /rob/gi
var match = stringToSearch( pattern );

This "should" return 3.

No comments: