Package org.xwiki.velocity.tools
Class RegexTool
- java.lang.Object
-
- org.xwiki.velocity.tools.RegexTool
-
public class RegexTool extends Object
Velocity Tool offering various Regex-based APIs to make it easy to manipulate regular expressions from Velocity.- Since:
- 2.0RC2
- Version:
- $Id: ba5f8901e072682cfd69bca5cd24d4212ef0563e $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
RegexTool.RegexResult
Result of a Regex search.
-
Constructor Summary
Constructors Constructor Description RegexTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pattern
compile(String regex)
Compiles a regular expression into a javaPattern
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 patternString
for the specifiedString
.String
quoteReplacement(String s)
Returns a literal replacementString
for the specifiedString
.
-
-
-
Method Detail
-
find
public List<RegexTool.RegexResult> find(String content, String regex)
- Parameters:
content
- the content to parseregex
- the regex to look for in the passed content- Returns:
- empty list if the passed regex doesn't match the content or several
RegexTool.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 pattern
-
findAll
public List<List<RegexTool.RegexResult>> findAll(String content, String regex)
- Parameters:
content
- the content to parseregex
- the regular expression to look for in the passed content- Returns:
- an empty list if the passed regular expression doesn't match the content, several
RegexTool.RegexResult
objects containing the matched position and matched content for all capturing groups and sub-groups otherwise
-
compile
public Pattern compile(String regex)
Compiles a regular expression into a javaPattern
object.- Parameters:
regex
- the textual representation of the regular expression- Returns:
- the
Pattern
object corresponding to the regular expression, ornull
if the expression is invalid - Since:
- 2.3M1
-
quote
public String quote(String s)
Returns a literal patternString
for the specifiedString
.This method produces a
Metacharacters or escape sequences in the input sequence will be given no special meaning.String
that can be used to create aPattern
that would match the strings
as if it were a literal pattern.- Parameters:
s
- The string to be literalized- Returns:
- A literal string replacement
- Since:
- 2.4M2
-
quoteReplacement
public String quoteReplacement(String s)
Returns a literal replacementString
for the specifiedString
. This method produces aString
that will work as a literal replacements
inString#replaceAll(regularExpression, s)
. TheString
produced will match the sequence of characters ins
treated as a literal sequence. Slashes ('\') and dollar signs ('$') will be given no special meaning.- Parameters:
s
- the string to be literalized- Returns:
- a literal string replacement
- Since:
- 8.2RC1
-
-