2010-04-14 - Jakarta Taglibs has been retired.

For more information, please explore the Attic.

Tag reference sheet

Tag library reference for the following tag libraries:

Regexp Tag library

null null null null

This is version 1.0.1.

  • existsMatch Uses a regexp to determine if a match exists in the text
  • group Get the value of a single parenthesized group within a single match
  • match Loops through each match found in a text string by a regexp
  • regexp Create a regular expression script variable
  • split Implements a perl style split on the text
  • substitute Performs a string substitution on text using a regexp
  • text Create a text string script variable for use with a regexp

Required attributes are marked with a *

<regexp:existsMatch>

Uses a regexp to determine if a match exists in the text.

Can contain: JSP

Example

          null

<%-- create the match regexp "m/test1/mi" --%>
<rx:regexp id="rx1">m/test1/mi</rx:regexp>
<%-- set the text to match on --%>
<rx:text id="test">
This is a
test of regular expression matching.
</rx:text>
See if a match exists...<br>
<rx:existsMatch regexp="rx1" text="test">
     A match was found!<br>
</rx:existsMatch>
<rx:existsMatch regexp="rx1" text="test" value="false">
     A match was not found!<br>
</rx:existsMatch>
      

Attributes

Name Description Type
regexp* Script variable id of null to use for match. String
text* Script variable id of null to check for a match. String
value If value is set to null the existsMatch tag includes body of tag if a match does not exist. Default is null. String

<regexp:group>

Get the value of a single parenthesized group within a single match.

Can contain: empty

Example

          null

<%-- set the text to perform match --%>
<rx:text id="test">            
This is                              
test1 of a regular expression match,
on words that start with 'i' like item and
index, the group tag will be used to get the
next word after the word starting with 'i'.
</rx:text>                     
<%-- create the match regexp "m/\si[^\s]*\s([^\s]+)/mi" --%>
<rx:regexp id="rx4">m/\si[^\s]*\s([^\s]+)/mi</rx:regexp>
<pre>                          
<rx:match id="mtch" text="test" regexp="rx4">
   Match: <jsp:getProperty name="mtch" property="match"/><br>
    Parenthesized Group 1: <rx:group number="1"/>
</rx:match></pre>
      

Attributes

Name Description Type
number* Parenthesised group number to get from match. String

<regexp:match>

Loops through each match found in a text string by a regexp.

Can contain: JSP

Example

          null

<%-- set the text to perform match --%>
<rx:text id="test">            
This is                              
test1 of a regular expression match,
on words that start with 'i' like item and
index.                               
</rx:text>                     
<%-- create the match regexp "m/\si[^\s]*\s/mi" --%>
<rx:regexp id="rx4">m/\si[^\s]*\s/mi</rx:regexp>
<pre>                          
<rx:match id="mtch" text="test" regexp="rx4">
   Match: <jsp:getProperty name="mtch" property="match"/><br>
    Pre Match: <jsp:getProperty name="mtch" property="preMatch"/><br>
    Post Match: <jsp:getProperty name="mtch" property="postMatch"/><br>
</rx:match>
      

Attributes

Name Description Type
id* Script variable id for use with standard null tag. String
regexp* Script variable id of null to use for match. String
text* Script variable id of null to perform match on. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.regexp.MatchTag NESTED Match Data Bean

<regexp:regexp>

Create a regular expression script variable.

Can contain: JSP

Example

          Enter a JSP comment without the opening and closing tags.
              Those will be added by the XSL.  Put no HTML mark-up in here.
              Currently, only one comment per usage section is supported. 
          null

           The code element is for an example of using the tag.  I
               normally put these in CDATA sections so that the XSL
               transform to HTML will turn the angle brackets into the
               appropriate &lt; and &gt; entities automatically. Only
               one code element per usage element is supported.
               The resultant HTML is formatted and colorized. 
<rx:regexp id="rx1">m/test1/mi</rx:regexp>
The regular expression is:
<jsp:getProperty name="rx1" property="regexp"/>
      

Attributes

Name Description Type
id* Script variable id for use with standard null tag and as an attribute to other tags in this tag library. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.regexp.RegexpData AT_BEGIN Regular Expression Bean

<regexp:split>

Implements a perl style split on the text.

Can contain: JSP

Example

          null

<%-- set the text to split --%>
<rx:text id="test">
This is
test1 of a regular expression split,
on whitespace, and then on a comma.
</rx:text>
<ul>
<rx:split id="split" text="test">
   <jsp:getProperty name="split" property="split"/><br>
</rx:split>
</ul>
<%-- now split the text using a comma with limit of 2 --%>
<rx:regexp id="rx3">/,/m</rx:regexp>
<ul>
<rx:split id="split" text="test" regexp="rx3" limit="2">
   <jsp:getProperty name="split" property="split"/><br>
</rx:split>
</ul>
      

Attributes

Name Description Type
id* Script variable id for use with standard null tag. String
limit Set a limit for the number of strings split out from text. String
regexp Script variable id of null to use for split. If no null is used the split will be done based on whitespace. String
text* Script variable id of null to perform split on. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.regexp.SplitTag NESTED Split Data Bean

<regexp:substitute>

Performs a string substitution on text using a regexp.

Can contain: JSP

Example

          null

<%-- create the substitute regexp "s/test1/test2/gmi" --%>
<rx:regexp id="rx2">s/test1/test2/gmi</rx:regexp>   
<%-- set the text to match on --%>                        
<rx:text id="test">                                    
This is                                 
test1 of regular expression substitution.
</rx:text>                         
Here is the text after substitution...<br>
<rx:substitute regexp="rx2" text="test"/>
      

Attributes

Name Description Type
regexp* Script variable id of null to use for substitute. String
text* Script variable id of null to perform substitution on. String

<regexp:text>

Create a text string script variable for use with a regexp.

Can contain: JSP

Example

          null
<rx:text id="tx1">This is a test string.</rx:text>
The text string is:
<jsp:getProperty name="tx1" property="text"/>
      

Attributes

Name Description Type
id* Script variable id for use with standard null tag and as an attribute to other tags in this tag library. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.regexp.TextData AT_BEGIN Text String Bean