Saturday, 4 October 2014

Regular Expressions

Regular expressions are powerful tool for text processing. A regular expression is a sequence of characters that forms a search pattern, mainly used for pattern matching in strings. Regular Expressions are used to search, edit, or manipulate text and data. Once you comfortable in regular expressions, you will find the advantage of regular expressions.

'java.util.regex' package provides Classes for matching character sequences against patterns specified by regular expressions. The regular expression syntax in the java.util.regex API is most similar to that found in Perl.

A Regular expression is composed of two types of characters.
a. Metacharacters (*, ., ?, ^, $ etc.,) : Metacharacters have special meaning.
b. Literals : Normal characters without special meaning.

For Ex: a*b
a,b are literals and '*' is the metacharacter. 'a*b' matches strings like b, ab, aab, aaab, aaaaab etc.,

a* means 'a' can be repeated zero or more times.

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment