Java Reference
In-Depth Information
The replaceFirst() method replaces the first occurrence of the match with the replacementString . It returns
the new string after replacement. Some examples of using the replaceFirst() method are as follows:
String regex = ".@.";
// newStr will contain "webmaste***dojo.com"
String newStr = "webmaster@jdojo.com".replaceFirst(regex, "***");
// newStr will contain "***"
newStr = "A@B".replaceFirst(regex, "***");
// newStr will contain "***andH@G"
newStr = "A@BandH@G".replaceFirst(regex, "***");
// newStr will contain "B%T" (same as the original string)
newStr = "B%T".replaceFirst(regex, "***");
Metacharacters
Metacharacters are characters with special meanings. They are used in regular expressions. Sometimes
metacharacters do not have any special meanings and they are treated as ordinary characters. They are treated
as ordinary characters or metacharacters depending on the context in which they are used. The metacharacters
supported by the regular expressions in Java are as follows:
( (a left parenthesis)
) (a right parenthesis)
[ (a left bracket)
] (a right bracket)
{ (a left brace)
{ (a right brace)
\ (a backslash)
^ (a caret)
$ (a dollar sign)
| (a vertical bar)
? (a question mark)
* (an asterisk)
+ (an addition sign)
. (a dot or period)
< (a less-than sign)
> (a greater-than sign)
- (a hyphen)
= (an equal to sign)
! (an exclamation mark)
 
Search WWH ::




Custom Search