public class Regex extends Regex
This is an extension to the com.stevesoft.pat.Regex class. It adds support for named capturing groups and named backreferences but group names in replace rules are not supported so far. Group names and backreference names must be surrounded in <> brackets, e.g. Regex("(?<x>abc|def)=\k<x>") will match abc=abc or def=def, but not abc=def or def=abc Duplicate group names are not supported and will cause a compile error.
dotDoesntMatchCR, esc
charsMatched_, didMatch_, marks, matchFrom_, numSubs_, src
Constructor and Description |
---|
Regex()
Initializes the object without a Pattern.
|
Regex(String prepat)
Create and compile a Regex (possibly with named groups), but
do not throw any exceptions.
|
Modifier and Type | Method and Description |
---|---|
void |
compile(String prepat)
This method compiles a regular expression, making it
possible to call the search or matchAt methods.
|
String |
getCompileError()
Returns the error message that might be generated during the
pattern compilation.
|
Hashtable |
getNamedGroups()
Returns the Hashtable holding the named groups of the pattern
|
String |
getOriginalPattern()
Returns the original pattern passed to this class.
|
String |
getPattern()
Returns the pattern after the named groups and backreferences
have been removed, so it can be used by the com.stevesoft.pat package
|
boolean |
isPatternCompiled()
Checks, if the pattern is compiled successfully
|
String |
stringMatched(String groupName)
Obtains a substring matching the named set
of parenthesis from the pattern or null if there is no group
with this name
|
accept, add, clone, compile1, countMaxChars, countMinChars, define, define, equals, getDefaultMFlag, getDontMatchInQuotes, getGFlag, getIgnoreCase, getMFlag, getReplacer, getReplaceRule, getSFlag, isDefined, isLiteral, matchAt, matchAt, optimize, optimized, perlCode, replaceAll, replaceAll, replaceAllFrom, replaceAllRegion, replaceFirst, replaceFirstFrom, replaceFirstRegion, result, reverseSearch, reverseSearch, search, search, searchFrom, searchFrom, searchRegion, setDefaultMFlag, setDontMatchInQuotes, setGFlag, setIgnoreCase, setReplaceRule, setReplaceRule, toString, undefine, version
charsMatched, charsMatched, copyOutOf, didMatch, equals, getString, getStringLike, left, left, matchedFrom, matchedFrom, matchedTo, matchedTo, matchFrom, matchFrom, numSubs, right, right, stringMatched, stringMatched, substring, substring
public Regex()
compile(java.lang.String)
public Regex(String prepat)
isPatternCompiled()
,
getCompileError()
public void compile(String prepat) throws RegSyntax
compile
in class Regex
RegSyntax
- is thrown if a syntax error is encountered
in the pattern.
For example, "x{3,1}" or "*a" are not valid
patterns.Regex.search(java.lang.String)
,
Regex.matchAt(java.lang.String, int)
public String getCompileError()
public Hashtable getNamedGroups()
public String getOriginalPattern()
public String getPattern()
public boolean isPatternCompiled()