Download presentation
Presentation is loading. Please wait.
Published byCordelia Jackson Modified over 8 years ago
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 substringsmatch() –search() returns the position of the first matchsearch() –replace() returns the new string with replaced textreplace() JavaScript also has a special RegExp objectRegExp
4
Learning regex Best online resource and tutorials: http://www.regular-expressions.info http://www.regular-expressions.info Online playground: http://gskinner.com/RegExr/ http://gskinner.com/RegExr/ Exercises: http://regex.sketchengine.co.uk/ http://regex.sketchengine.co.uk/
5
Basic steps for creating a regex pattern 1.Define very clearly which kinds of text you want to match 2.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 3.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 helponline regex tool
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.