public class RegexTool extends Object
Modifier and Type | Class and Description |
---|---|
class |
RegexTool.RegexResult
Result of a Regex search.
|
Constructor and Description |
---|
RegexTool() |
Modifier and Type | Method and Description |
---|---|
Pattern |
compile(String regex)
Compiles a regular expression into a java
Pattern object. |
List<RegexTool.RegexResult> |
find(String content,
String regex) |
List<List<RegexTool.RegexResult>> |
findAll(String content,
String regex) |
String |
quote(String s)
Returns a literal pattern
String for the specified String . |
String |
quoteReplacement(String s)
Returns a literal replacement
String for the specified String . |
public List<RegexTool.RegexResult> find(String content, String regex)
content
- the content to parseregex
- the regex to look for in the passed contentRegexTool.RegexResult
objects
containing the matched position and matched content for all capturing groups, the first group
representing the whole . The first object is represents the entire patternpublic List<List<RegexTool.RegexResult>> findAll(String content, String regex)
content
- the content to parseregex
- the regular expression to look for in the passed contentRegexTool.RegexResult
objects containing the matched position and matched content for all capturing groups and sub-groups
otherwisepublic Pattern compile(String regex)
Pattern
object.regex
- the textual representation of the regular expressionPattern
object corresponding to the regular expression, or null
if the expression is
invalidpublic String quote(String s)
String
for the specified String
.
This method produces a String
that can be used to create a Pattern
that would match the
string s
as if it were a literal pattern.
s
- The string to be literalizedpublic String quoteReplacement(String s)
String
for the specified String
. This method produces a
String
that will work as a literal replacement s
in
String#replaceAll(regularExpression, s)
. The String
produced will match the sequence of
characters in s
treated as a literal sequence. Slashes ('\') and dollar signs ('$') will be given no
special meaning.s
- the string to be literalizedCopyright © 2004–2021 XWiki. All rights reserved.