Presentation is loading. Please wait.

Presentation is loading. Please wait.

Regular Expressions: The Proper Care and Feeding Zain Naboulsi MSDN Developer Evangelist Microsoft.

Similar presentations


Presentation on theme: "Regular Expressions: The Proper Care and Feeding Zain Naboulsi MSDN Developer Evangelist Microsoft."— Presentation transcript:

1 Regular Expressions: The Proper Care and Feeding Zain Naboulsi MSDN Developer Evangelist Microsoft

2 Introduction to Regular Expressions What Are Regular Expressions? Why Would I Want To Use Them? Common Misconceptions Anatomy of An Regular Expression

3 Disclaimer All opinions in this session are provided "AS IS" with no warranties, and confer no rights. All opinions are my mine and don't necessarily reflect the opinion of Microsoft. All opinions are my mine and don't necessarily reflect the opinion of Microsoft.

4 What Are Regular Expressions?

5 Regular Expressions “Regular expressions provide a powerful, flexible, and efficient method for processing text. [They allow] you to quickly parse large amounts of text to find specific character patterns; to extract, edit, replace, or delete text substrings; or to add the extracted strings to a collection in order to generate a report.” http://msdn2.microsoft.com/en-us/library/hs600312.aspx http://msdn2.microsoft.com/en-us/library/hs600312.aspxhttp://msdn2.microsoft.com/en-us/library/hs600312.aspx

6 Do What? Simply put, regular expressions will help you find text patterns and do pretty much whatever you want to it. It sounds simple but regular expressions are one of the most difficult and least understood constructs in programming.

7 Warning Regular expressions are part art and part science. There is a steep learning curve but the rewards are significant.

8 The Possibilities

9 Okay, So What Is A Pattern? “a regular or repetitive form, order, or arrangement” http://encarta.msn.com/dictionary_1861724272/pattern.html

10 PATTERNS ARE EVERYWHERE

11 Checker Board

12 Fibonacci Sequence

13 Text The IP Address for the server is 192.169.1.3 but it should be 192.168.1.5, and I am not sure how we managed to get into the 192.169.1 subnet but we need to remove ourselves from it immediately unless we are moving to it then I want the new IP to be 192.169.1.3 I suppose.

14 YOU HAVE USED PATTERNS BEFORE

15 Wildcard Searches For Files Wildcards = VERY simple pattern matching constructs and are NOT regular expressions Examples:*.txtb*b*?un.txt

16 Why Use Regular Expressions?

17 Major Uses of Regular Expressions Matching = find any text anywhere regardless of complexity Substitution = once found, you can replace text

18 Features Can literally turn 10 lines of code into 1 Extremely efficient pattern matching mechanism Once learned, becomes one of the most indispensible techniques you can have

19 Languages That Support Regular Expressions All.NET languages JScript XML: XPath & XQuery T-SQLPERLJava [insert language here]

20 ASP.NET Control

21 Common Misconceptions

22 Misconceptions Regular Expressions can do complex programming logic Regular Expressions can do math Regular Expressions will give me winning lottery numbers

23 Anatomy of an Regular Expression

24 A Sample Expression ^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$

25 Anatomy CharactersMetacharactersSubexpressions

26 Characters A literal character represents any valid value represented by the current encoding method. For example the “@” literal character is represented as the decimal value 65 in the ASCII encoding system. ^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$

27 Metacharacters Unlike literal characters, metacharacters are used as “place holders” for characters. For example, the metacharacter “\t” in regular expressions represents the tab character, whereas the “\d” matches any digit 0 through 9. ^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$

28 Subexpressions These are simply smaller expressions nested inside larger ones. For example, the following expression has a subexpression inside it: (john|jane)doe

29 Must Have Resources

30 Tools http://www.RegExLib.com http://www.ultrapico.com/Expresso.htm

31 Book

32 Tools

33 Summary

34 Summary Regular expressions can be used to manipulate and change text While there is a steep learning curve, regular expressions are invaluable as a programming tool Regular expressions are supported by virtually all major programming languages

35 Next Steps Check out some of the patterns on the RegExLib site Do a live search on regular expressions and see what others have to say about them Prepare your self mentally for a rewarding journey into the world of regular expressions Have Fun!!!

36


Download ppt "Regular Expressions: The Proper Care and Feeding Zain Naboulsi MSDN Developer Evangelist Microsoft."

Similar presentations


Ads by Google