Presentation is loading. Please wait.

Presentation is loading. Please wait.

Regular Expressions.

Similar presentations


Presentation on theme: "Regular Expressions."— Presentation transcript:

1 Regular Expressions

2 Contents Splitting Strings Replacing Strings Matching Strings
Extracting Strings Regex Concepts

3 1. Splitting Strings Test case 1: Given a full name, break it into discrete name parts separated by one or more spaces

4 Test case 2: Similar to the previous case but the separator can be either | or # along with padding spaces

5 2. Replacing Strings Test case: Given a phone number, strip all nondigits (parentheses, hyphens, letters, whitespace, and so on) from it

6 3. Matching/Validating Strings
Test case 1: Check if a string is an number or not 6

7 Test case 2: Check if a string starts with comment symbol // or not

8 Test case 3: Check if a string is in time format or not

9 Check if a string is a 5-digit ZIP code

10 Check if a date is in the MM/DD/YYYY format
The year can only 2 digits or 4 digits

11 LocalName: Any alphanumeric, as well as ., -, _, and +
LocalName: Any alphanumeric, as well as ., -, _, and + DomainPrefix: Any alphanumeric, as well as - DomainSuffix: Can appear one or more times of the following Any 2-, 3-, or 4-character alphanumeric preceded by a period. (The period is considered part of the domain suffix)

12 4. Extracting Strings Test case: Given a phone message, extract phone numbers (sequence of digits) inside it

13

14 5. Regex Concepts Regular expressions (Regex) are used to specify string patterns. You can use regular expressions whenever you need to locate strings that match a particular pattern

15 5. Regex Syntax

16

17

18 References Core Java, Volume II – Advanced Features, Eighth Edition, Chapter 1. Cay S. Horstmann and Gary Cornell. Prentice Hall, 2008


Download ppt "Regular Expressions."

Similar presentations


Ads by Google