1 / 5

Post-Module JavaScript

Post-Module JavaScript. BTM 395: Internet Programming. Regular expressions (regex). Search and replace on steroids Lets you search for any kind of text, even with variable content Includes variables (back-references) for dynamic replacements

bond
Download Presentation

Post-Module JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Post-Module JavaScript BTM 395: Internet Programming

  2. Regular expressions (regex) • Search and replace on steroids • Lets you search for any kind of text, even with variable content • Includes variables (back-references) for dynamic replacements • Available in virtually every programming language, most text editors, and even Microsoft Word (called wildcards)

  3. Regex in JavaScript • All JavaScript strings support the following functions: • match() returns an array of matched substrings • search() returns the position of the first match • replace() returns the new string with replaced text • JavaScript also has a special RegExp object

  4. Learning regex • Best online resource and tutorials: http://www.regular-expressions.info • Online playground: http://gskinner.com/RegExr/ • Exercises: http://regex.sketchengine.co.uk/

  5. Basic steps for creating a regex pattern • Define very clearly which kinds of text you want to match • Define very clearly which kinds of text you do NOT want to match • This step is optional if you are creating a quick and dirty solution • This step is essential if you are creating a solution that will treat uncertain user input • Experiment with sample text (both of what you want and of what you don’t want) until you get the right pattern • An online regex tool can help

More Related