Presentation is loading. Please wait.

Presentation is loading. Please wait.

Michael Olivero Microsoft Student Ambassador for FIU Special Guest: FIU Graduate Student Miguel Gonzalez.

Similar presentations


Presentation on theme: "Michael Olivero Microsoft Student Ambassador for FIU Special Guest: FIU Graduate Student Miguel Gonzalez."— Presentation transcript:

1 Michael Olivero Microsoft Student Ambassador for FIU mike@mike95.com Special Guest: FIU Graduate Student Miguel Gonzalez

2 Topics Covered Today  Intro to ASP.NET  Regular Expressions (Regex)  Web Services

3 Brief Intro  Client Server Model (State)

4 Brief Intro  Client Server Model (State Less)

5 What happens when you request a web page My Picture My picture is: Each resource is requested with a separate connection.

6 The need for dynamic data - CGI

7 Issues with CGI  Multiple Processes  Integration with Content creates cluttered code  Ex: C++ code to write HTML code

8 Come Active Server Pages  Why not mix the code within the HTML page?

9 code ASP Processing

10 Issues with ASP  Parsing overhead  Interpretation overhead  Mixing of presentation & code  All the issues of a non-OOP language  No encasulation  No inheritance  Etc.

11 Come ASPX  Why not create a model from the ground up to resolve all of these issues…  Every page is a OOP class  Content is separate from code  Compiled code not interpreted  Inheritance  Reuse  …and the list goes on Coming Spring 2004

12 Quick Demo ASPX

13 Topics Covered Today Intro to ASP.NET Intro to ASP.NET  Regular Expressions (Regex)  Web Services

14 Intro to parsing…  How many times have you parsed a string?  What did you use?  Substring()  IndexOf()

15 Parsing using String class methods  Example  Given an email like mike@mike95.com you want to pull out the first part of the domain name “mike95” mike@mike95.com  Sample code using string class methods: String email = “mike@mike95.com”; String domain = email.substring( email.IndexOf(‘@’), email.lastIndexOf(‘.’) – email.IndexOf(‘@’) );

16 Parsing using Regex  Example  Given an email like mike@mike95.com you want to pull out the first part of the domain name “mike95” mike@mike95.com  Sample code using string class methods: String email = “mike@mike95.com”; Match m = Regex.Match( email, “[^\@]*@([^.]*)” );

17 Regular Expressions Miguel Gonzalez  What are they? (5-6 min)  Regex vs Linear String searches (5-6min)  Regex in.NET (10 min)  Classes  Basic Options  In-Depth Regex (15 min)  Advanced Regex in.NET (5 min)

18 Regex Foundation  What are regular expressions?  A powerful technique to process textual data  Description of machine that “eats” strings  How do they work internally?  DFA  NFA .NET implementation is NFA-based  Examples:  ^from:.* .*\b.NET\b.*  [0-9]+

19 DFA: Deterministic Finite Automata  The machine is deterministic:  One line of execution  Greedy Little Machine  Always finds the longest match.  Tracks all possible matches simultaneously  Cannot backtrack  Cannot remember captured subexpressions  Cannot “look ahead” or “look behind”  Cannot be “lazy”  Example:  Find a price in different coins:  ((US|CAN)$|EU)[0-9]+\.[0-9][0-9]

20 NFA: Non-Deterministic Finite Automata  Warning for the Purists: Not a “real” NFA  The machine is non-deterministic:  Multiple possible lines of execution  Has to run through every choice.  Can save points of execution and “backtrack”  Capture sub-expressions  Greedy, but can be Lazy when it wants to  Example:  Find a price:  ((US|CAN)$|EU)[0-9]+\.[0-9][0-9]

21 Regular Expressions vs Traditional String Matching  Efficiency  Conciseness  Simplicity  Demo

22 Regex Syntax  Character matching  Literals:  John Smith  Character classes  Pre-Defined  Word Character: \w  Whitespace: \s  Digits: \d  Anything:.  Negation: \W, \S, \D  User defined  [mnopq]  Negation: [^mnopq]  Ranges  [a-z], [0-9]  [0-9a-f]  Demo

23 Regex Syntax  Position  Start of line: ^  End of line: $  Match a word: \b  Match a substring: \B  Demo

24 Regex Syntax  Quantifiers  Zero or more: *  One or more: +  Optional (zero or one) : ?  Being exact: {n}, {n,} {n,m}  Lazy Quantifiers: Add an extra ? Symbol  Example: a*?  Demo

25 Regex Syntax  Grouping expressions  Unnamed:.*year.*(\d\d\d\d)  Named:.*year.*(? \d\d\d\d)  ORing expressions: ab | cd  Backreference  By index: \n  By name \k  By name \k  Demo

26 Regex in.NET .NET Regex implementation  NFA-based  Regex Cache  Classes  System.Text.RegularExpressions  Basic.NET Options  Regex Compilation in.NET

27 Regex Object  Creating Regexes  new Regex( regex)  new Regex( regex, options)  Matching  Regex.isMatch(target)  Regex.isMatch(target, offset)  For more complex behavior: Obtain and use Match object

28 String Manipulation with Regex  String replacement  Methods  Regex.Replace(target, replacement)  Regex.Replace(target, replacement, count)  Regex.Replace(target, replacement, count, offset)  Can refer to matches in the regex through escape codes:  Matched text: $& or $0  Matched text for Groups: $1 … $N or ${name}  Text before the match: $`  Text after the match: $’  Original text: $_  Example:  Generate a reply To header from the From header of the original email  new Regex(“^From”).Replace(“To:$’”)  String splitting  Methods  Regex.split(target)  Regex.split(target, count)  Regex.split(target, count, offset)

29 Match Object  Represent the result of applying the Regex  Get a Match Object from Regex  Regex.Match(target)  Regex.Match(target, offset)  Regex.Match(target, offset, maxlength)  Get all the matches  Regex.Matches(target)  Regex.Matches(target, offset)  Properties  Match.Success  Match.Length  Match.Index  Match.Groups  Match.Captures  Methods  Match.Result(string)  Match.NextMatch()  Match.Synchronized()

30 Groups  Represent groupings in the Regex .NET Regex Groups can be named  Properties  Group.Success  Group.Value  Group.Length  Group.Index  Group.Captures Captures  Represent intermediary matchings in the working process of the regex/group  Properties  Group.Success  Group.Value  Group.Length  Group.Index  Group.Captures

31 .NET Shortcuts  Regex Convenience Methods  Matching  Regex.Match(pattern, target)  Regex.Match(pattern, target, options)  Regex.IsMatch(pattern, target)  Regex.IsMatch(pattern, target, options)  Regex.Matches(pattern, target)  Regex.Matches(pattern, target, options)  String Replacement  Regex.Replace(pattern, target, replacement)  Regex.Replace(pattern, target, replacement, options)  String Splitting  Regex.Split(pattern, target)  Regex.Split(pattern, target, options)  String Escaping  Regex.Escape(string)  Regex.Unescape(string)

32 Regex Options in.NET  Regex.IgnoreCase  Regex.IgnorePatternWhitespace  Regex.Multiline  Regex.Singleline  Regex.ExplicitCapture  Regex.ECMAScript  Regex.Compiled  Regex.RightToLeft

33 Regex Compilation in.NET .NET Compilation  Optimizes the NFA for speed  Overhead at object creation  Increased memory cost .NET Compilation to Assembly  Compiles Regex as an MSIL object  Optimizes speed and memory  Demo

34 Topics Covered Today Intro to ASP.NET Intro to ASP.NET Regular Expressions (Regex) Regular Expressions (Regex)  Web Services


Download ppt "Michael Olivero Microsoft Student Ambassador for FIU Special Guest: FIU Graduate Student Miguel Gonzalez."

Similar presentations


Ads by Google