The Regexp custom tag library contains tags which can be used to perform Perl syntax regular expressions.
These tags implement the three most common Perl5 operations involving regular expressions:
For more information on how to use Perl syntax regular expressions you can start at the Perl Regular Expression page. http://www.perl.com/pub/doc/manual/html/pod/perlre.html
If you search the web you can find thousands of web sites documenting how to use perl regular expressions.
This custom tag library requires no software other than a servlet container that supports the JavaServer Pages Specification, version 1.1 or higher. And Version 2.0 of the Jakarta ORO Perl Regular Expression package.
Follow these steps to configure your web application with this tag library:
<taglib> <taglib-uri>http://jakarta.apache.org/taglibs/regexp-1.0</taglib-uri> <taglib-location>/WEB-INF/regexp.tld</taglib-location> </taglib>
To use the tags from this library in your JSP pages, add the following directive at the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/regexp-1.0" prefix="rx" %>
where "rx" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.
regexp | Create a regular expression script variable. |
text | Create a text string script variable for use with a regexp. |
existsMatch | Uses a regexp to determine if a match exists in the text. |
substitute | Performs a string substitution on text using a regexp. |
split | Implements a perl style split on the text. |
match | Loops through each match found in a text string by a regexp. |
group | Get the value of a single parenthesized group within a single match. |
regexp | Availability: 1.0 | ||||
Create a regular expression script variable. |
|||||
Tag Body | JSP | ||||
Restrictions |
The body of the tag is assigned to a script variable as a regular expression. |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable id for use with standard jsp:getProperty tag and as an attribute to other tags in this tag library. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | Start of tag to end of page | 1.0 | |||
Regular Expression Bean |
|||||
Properties | Name | Get | Set | Availability | |
regexp | Yes | No | 1.0 | ||
Returns the text of the regular expression. |
|||||
Examples | Create a match regular expression scripting variable. | ||||
|
text | Availability: 1.0 | ||||
Create a text string script variable for use with a regexp. |
|||||
Tag Body | JSP | ||||
Restrictions |
The body of the tag is assigned to a script variable as a text string. |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable id for use with standard jsp:getProperty tag and as an attribute to other tags in this tag library. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | Start of tag to end of page | 1.0 | |||
Text String Bean |
|||||
Properties | Name | Get | Set | Availability | |
text | Yes | No | 1.0 | ||
Returns the text string. |
|||||
Examples | Create a text string scripting variable. | ||||
|
existsMatch | Availability: 1.0 | ||||
Uses a regexp to determine if a match exists in the text. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
regexp | Yes | No | 1.0 | ||
Script variable id of regexp to use for match. |
|||||
text | Yes | No | 1.0 | ||
Script variable id of text to check for a match. |
|||||
value | No | No | 1.0 | ||
If value is set to false the existsMatch tag includes body of tag if a match does not exist. Default is true. |
|||||
Variables | None | ||||
Examples | Determine if a match can be found in a text string using a regular expression. | ||||
|
substitute | Availability: 1.0 | ||||
Performs a string substitution on text using a regexp. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
regexp | Yes | No | 1.0 | ||
Script variable id of regexp to use for substitute. |
|||||
text | Yes | No | 1.0 | ||
Script variable id of text to perform substitution on. |
|||||
Variables | None | ||||
Examples | Substitute "test2" for "test1" in a text string. | ||||
|
split | Availability: 1.0 | ||||
Implements a perl style split on the text. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable id for use with standard jsp:getProperty tag. |
|||||
regexp | No | No | 1.0 | ||
Script variable id of regexp to use for split. If no regexp is used the split will be done based on whitespace. |
|||||
text | Yes | No | 1.0 | ||
Script variable id of text to perform split on. |
|||||
limit | No | No | 1.0 | ||
Set a limit for the number of strings split out from text. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | Nested within tag | 1.0 | |||
Split Data Bean |
|||||
Properties | Name | Get | Set | Availability | |
split | Yes | No | 1.0 | ||
Returns the string split out from text. |
|||||
Examples | First perform a split of a text string on whitespace, then perform a split on the character ','. | ||||
|
match | Availability: 1.0 | ||||
Loops through each match found in a text string by a regexp. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable id for use with standard jsp:getProperty tag. |
|||||
regexp | Yes | No | 1.0 | ||
Script variable id of regexp to use for match. |
|||||
text | Yes | No | 1.0 | ||
Script variable id of text to perform match on. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | Nested within tag | 1.0 | |||
Match Data Bean |
|||||
Properties | Name | Get | Set | Availability | |
match | Yes | No | 1.0 | ||
Returns the entire string that was matched on. |
|||||
preMatch | Yes | No | 1.0 | ||
Returns the string preceding the current match. |
|||||
postMatch | Yes | No | 1.0 | ||
Returns the string after the current match. |
|||||
Examples | Use match to find all words in a text string that start with the letter 'i'. | ||||
|
group | Availability: 1.0 | ||||
Get the value of a single parenthesized group within a single match. |
|||||
Tag Body | empty | ||||
Restrictions |
Must be nested inside a match tag. |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
number | Yes | No | 1.0 | ||
Parenthesised group number to get from match. |
|||||
Variables | None | ||||
Examples | Use the group tag to get the next word in a text string after a word that starts with the letter 'i'. | ||||
|
See the example application regexp-examples.war for examples of the usage of the tags from this custom tag library.
Java programmers can view the java class documentation for this tag library as javadocs.
Review the complete revision history of this tag library.