Page

10.5.0- The RegExp Object

  by NT Community Manager.  

PublicCategorized as 10. The Scripting Objects.

Not tagged.
<< 10.4.3- The Text Stream ObjectChapter1010.5.1- RegExp Properties >>

The RegExp Object

The Regular Expression object, to give it its full name, is new in VBScript 5.0 and adds to the language something JavaScript developers haveenjoyed for ages. But what is a regular expression, and why have VBScriptdevelopers been missing out on this important feature? Rather than describe whatit is straightaway in rather abstract terms, I'm going to recount a short storyof my juvenile delinquent days, which will help you visualize why regularexpressions might be useful. Back to my Computer Science classes, when we werestarry-eyed by the stories of hackers breaking into the Pentagon files withlittle more than a Commodore Vic20, we were convinced that we could break intoanything too – well at least our colleagues' accounts, to check to see whethertheir coursework answers tallied with ours. Our coursework was stored on a UNIXsystem, and everybody kept theirs under a user account and password.

 

Now, one week we learned about the UNIX command GREP (it stands for Get Regular ExPression) and how it is used to look for a sequenceof characters. Rumor quickly passed that if you got onto the system and forcedit to make a dump of everything it had in its memory currently (known as a coredump), then you would come across the various user accounts logged on at thetime together with the unencrypted passwords. As these core dumps would oftenamount to thousands of pages it just wasn't feasible to check every page ofgarbled information by hand, for these few nuggets, but the GREP command couldbe used to sift through the information. As everybody's account in our classstarted with the prefix dh1 followed by another two numbers, it was possible toset the GREP command to search for this pattern of letters along with another 2characters after to locate the errant passwords. Not that we ever put them touse, of course.

 

So a regular expression is a sequence of characters, bothknown and unknown. You replace the unknown characters with wildcards. Theregular expression forms what is known as a searchstring. The search string is what the object will attempt to locatewithin the data. The RegExp object provides a setof properties and methods for manipulating this search string.

<< 10.4.3- The Text Stream ObjectChapter1010.5.1- RegExp Properties >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |