Wednesday, May 4, 2011

Using Regular expressions with String in java

Class String provides several methods for performing regular expression operations.
3 methods provides by strings are:

  • s.matches("regex")
  • s.split("regex")
  • s.replace("regex", "replacement")

matches() evaluates true if the WHOLE string can be matched with string s.
split() creates array with substrings of s divided at occurrence of "regex". "regex" is not included in the result.
replace() replaces "regex" with "replacement.

Basic regex expressions with String.matches()

No comments:

Post a Comment

Chitika