クラス Epitaph
public final class Epitaph extends Object
There are two ways to specify the regular expression pattern to be
used, either by call Epitaph.Builder.pattern(String)
and directly specifying
an arbitrary pattern as string, or by call
Epitaph.Builder.pattern(RegexPattern)
specifying it from a preset provided by
Epitaph
based on RegexPattern
.
You can also call Epitaph.Builder.option(EnumSet)
as optional and specify
options set based on RegexOption
to be used when parsing with regular
expressions.
For regular expression parsing, the find()
, lookingAt()
and matches()
methods are provided. For strings matched in the
regular expression parsing process, you can use group()
method to
get the string within the range of the currently matched index.
Specify the regex pattern as preset:
Epitaph epitaph = Epitaph.builder().pattern(RegexPattern.JAPANESE_ALPHABET).input("test").build();
epitaph.find();
epitaph.lookigAt();
epitaph.matches();
epitaph.group();
Specify the specific regex pattern:
Epitaph epitaph = Epitaph.builder().pattern("[A-Za-z]+").input("test").build();
epitaph.find();
epitaph.lookigAt();
epitaph.matmatchesch();
epitaph.group();
- 導入されたバージョン:
- 1.0.0
-
ネストされたクラスの概要
ネストされたクラス 修飾子とタイプ クラス 説明 static class
Epitaph.Builder
The builder class forEpitaph
. -
メソッドの概要
修飾子とタイプ メソッド 説明 static Epitaph.Builder
builder()
Returns the new instance ofEpitaph.Builder
.boolean
equals(Object o)
boolean
find()
Attempts to find the next subsequence of the input sequence that matches the pattern.String
group()
Returns the input subsequence matched by the previous match.int
hashCode()
boolean
lookingAt()
Attempts to match the input sequence, starting at the beginning of the region, against the pattern.boolean
matches()
Attempts to match the entire region against the pattern.String
replaceAll(@NonNull String replacement)
Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.String
replaceFirst(@NonNull String replacement)
Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.String
toString()
-
メソッドの詳細
-
builder
Returns the new instance ofEpitaph.Builder
.- 戻り値:
- The new instance of
Epitaph.Builder
-
find
public boolean find()Attempts to find the next subsequence of the input sequence that matches the pattern.This method starts at the beginning of this matcher's region, or, if a previous invocation of the method was successful and the matcher has not since been reset, at the first character not matched by the previous match.
If the match succeeds then more information can be obtained via the
start
,end
, andgroup
methods.- 戻り値:
true
if, and only if, a subsequence of the input sequence matches this matcher's pattern
-
lookingAt
public boolean lookingAt()Attempts to match the input sequence, starting at the beginning of the region, against the pattern.Like the
matches
method, this method always starts at the beginning of the region; unlike that method, it does not require that the entire region be matched.If the match succeeds then more information can be obtained via the
start
,end
, andgroup
methods.- 戻り値:
true
if, and only if, a prefix of the input sequence matches this matcher's pattern
-
matches
public boolean matches()Attempts to match the entire region against the pattern.If the match succeeds then more information can be obtained via the
start
,end
, andgroup
methods.- 戻り値:
true
if, and only if, the entire region sequence matches this matcher's pattern
-
replaceFirst
Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.This method first resets this matcher. It then scans the input sequence looking for a match of the pattern. Characters that are not part of the match are appended directly to the result string; the match is replaced in the result by the replacement string. The replacement string may contain references to captured subsequences as in the
Matcher.appendReplacement(java.lang.StringBuffer, java.lang.String)
method.Note that backslashes (
\
) and dollar signs ($
) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.Given the regular expression
dog
, the input"zzzdogzzzdogzzz"
, and the replacement string"cat"
, an invocation of this method on a matcher for that expression would yield the string"zzzcatzzzdogzzz"
.Invoking this method changes this matcher's state. If the matcher is to be used in further matching operations then it should first be reset.
- パラメータ:
replacement
- The replacement string- 戻り値:
- The string constructed by replacing the first matching subsequence by the replacement string, substituting captured subsequences as needed
- 例外:
NullPointerException
- Ifnull
is passed as an argument
-
replaceAll
Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string; each match is replaced in the result by the replacement string. The replacement string may contain references to captured subsequences as in the
Matcher.appendReplacement(java.lang.StringBuffer, java.lang.String)
method.Note that backslashes (
\
) and dollar signs ($
) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.Given the regular expression
a*b
, the input"aabfooaabfooabfoob"
, and the replacement string"-"
, an invocation of this method on a matcher for that expression would yield the string"-foo-foo-foo-"
.Invoking this method changes this matcher's state. If the matcher is to be used in further matching operations then it should first be reset.
- パラメータ:
replacement
- The replacement string- 戻り値:
- The string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed
- 例外:
NullPointerException
- Ifnull
is passed as an argument
-
group
Returns the input subsequence matched by the previous match.For a matcher m with input sequence s, the expressions m.
group()
and s.substring(
m.start(),
m.end())
are equivalent.Note that some patterns, for example
a*
, match the empty string. This method will return the empty string when the pattern successfully matches the empty string in the input.- 戻り値:
- The (possibly empty) subsequence matched by the previous match, in string form
- 例外:
IllegalStateException
- If no match has yet been attempted, or if the previous match operation failed
-
toString
-
equals
-
hashCode
public int hashCode()
-