Class Regexp
Convenience class for matching regular expressions with a Dfa.
If you don't need to store values in a Dfa but only want to check if a string
completely matches a regular expression, starts with or
contains a match, use this class.
This class can be used somewhat similar to Matcher.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioninttests whetherthismatches a prefix ofs.intTests whetherthismatches a prefix ofsstarting at positionpos.inttries to findthisins.intTries to findthisinsstarting at positionstart.getDfa()intlength()Returns the number of characters matched by the most recent match call to any ofmatches,atStartOforfind.booleanchecks if the whole input sequence can be matched.booleanchecks if the whole input sequence starting at positionposcan be matched.
-
Constructor Details
-
Regexp
Creates a
Regexpobject for the given regular expression.- Throws:
IllegalArgumentException- in caserecontains syntax errors.- See Also:
-
-
Method Details
-
getDfa
-
matches
checks if the whole input sequence starting at position
poscan be matched.- Returns:
trueiff the whole input sequence starting at positionposand ending ats.length()can be matched.
-
matches
checks if the whole input sequence can be matched. This method is equivalent to a call to
matches(s, 0). -
find
Tries to find
thisinsstarting at positionstart.- Returns:
- the position of the match within
s, i.e. not relative tostart. To get the length of the match, uselength(). If no match can be found, -1 is returned.
-
find
tries to find
thisins. This method is equivalent to a call tofind(s, 0). -
atStartOf
Tests whether
thismatches a prefix ofsstarting at positionpos.- Returns:
- the length of the match or -1.
-
atStartOf
tests whether
thismatches a prefix ofs. This method is equivalent to a call toatStartOf(s, 0). -
length
public int length()Returns the number of characters matched by the most recent match call to any of
matches,atStartOforfind.- Throws:
IllegalStateException- if the most recent application ofthisdid not yield a match.
-