Advertisement

Responsive Advertisement

Regular Expressions in Java

 Class 1:

Regular Expressions:
If we want to represent a group of strings according  to a particular pattern, then we should go for Regular Expressions.

Applications of Regular Expressions:

1.Validating forms

2.Pattern Matching

3.Translators Design like compilers and Interpreter Design

4.Digital Circuit Design

5.Communication protocols development like TCP/IP and UDP etc


Class 2:

Basic Pattern Expression Java Program:

find method attempts to find next match and retuns true if it is available.Otherwise returns false.

start method returns the starting index of all matching strings.

end method to returns the ending index+1 of all matched strings

group method rteuns the matched string.

Class 3:

Explanatation of class 2 program
.

Class 4:

Character Classes:



Class 5:

Pre-defined Character Classes


Note:
1)We need to use back slash inorder to escape default behaviour of backslash.
2). matches every thing except new line character.


Class 6:

Quantifiers

Class 7:

Split in Regex

Class 8:

Difference between String split and pattern split.

String tokenizer is present in util package.
By default, the regular expression of tokenizer is space and if you want to split using any other character pass it as new argument after target string.

Class9:

Examples of regex usage:

Class 10:

Regex for mail validation

Note:we will have gmail.com or yahoo.co.in or something.co.in.ap so we use ([.][a-zA-Z]+)+ and first letter should be alpha numeric.

Class 11:

More examples:

Class 12:

Program to check mobile number and mail id  is valid or not.

for mail id validation replace regex in above code with mail regex.

Class 13:


Class 14:

Post a Comment

0 Comments