Pattern Method Equivalents in java.lang.String
by, 04-26-2012 at 07:53 PM (394 Views)
Support of the regular expression is also present in java.lang.String via different methods which mimic the java.util.regex.Pattern behavior. From APIs, their key excerpts are shown below for convenience.
Public Boolean matches (String regex):
Show whether string will be matching with the regular expression or not. This methodís invocation of the form str.matches produces similar output that was produced by expression Pattern.matches.
Public string split (String regex,int limit):
This string is being split around given regular expression matches. This methodís invocation of form str.split produces similar output that was produced by expression Pattern.compiler (regex).split(str, n).
Public String split (String regex):
This string is being split around given regular expression matches. This method is same like the 2 argument split method invoked along with given expressions, & limited argument of 0.
Also, a replace method is present which makes the replacement of 1 CharSequence with the other:
Public String Replace (CharSequence target, CharSequence replacement):
Stringís every substring is replaced which matched the literal target sequence, along with literal replacement sequence. Replacement takes place from start to end of string.