⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regexp.jsp

📁 jakarta-taglibs
💻 JSP
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Jakarta REGEXP Taglib Example</title>
</head>
<body bgcolor="#FFFFFF">

<center>
<h1>
Jakarta REGEXP Taglib Example</h1></center>
<br>
<%@ taglib uri="http://jakarta.apache.org/taglibs/regexp-1.0" prefix="rx" %>
<p>
Create the match regexp "m/test1/mi"<br>
<rx:regexp id="rx1">m/test1/mi</rx:regexp>
<br>Setting the text to match on to<br>
<pre>
This is a
test of regular expression matching.
</pre>
<rx:text id="test">
This is a
test of regular expression matching.
</rx:text>
<br>Seeing 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>
<br>Setting the text to match on to<br>
<pre>
This is
test1 of regular expression matching,
I hope you like it, and will use it.
</pre>                              
<rx:text id="test1">
This is
test1 of regular expression matching,
I hope you like it, and will use it.
</rx:text>
<br>Seeing if a match exists...<br>
<rx:existsMatch regexp="rx1" text="test1"> 
   A match was found!<br>
</rx:existsMatch>    
<rx:existsMatch regexp="rx1" text="test1" value="false"> 
   A match was not found!<br>                 
</rx:existsMatch>
<br>Create the substition regexp "s/test1/test2/gmi"<br>
<rx:regexp id="rx2">s/test1/test2/gmi</rx:regexp>
<br>Here is the last text after substitution<br>
<pre><rx:substitute regexp="rx2" text="test1"/></pre>
<br>Now lets split the above text on whitespace<br>
<ul>
<rx:split id="split" text="test1"><jsp:getProperty name="split" property="split"/><br></rx:split>
</ul>
<rx:regexp id="rx3">/,/m</rx:regexp>
<br>Now lets split the above text on a ","<br>
<ul>
<rx:split id="split" text="test1" regexp="rx3"><jsp:getProperty name="split" property="split"/><br></rx:split>
</ul>
<br>Now lets split the above text on a ",", but limit it to 2 items<br>
<ul>
<rx:split id="split" text="test1" regexp="rx3" limit="2"><jsp:getProperty name="split" property="split"/><br></rx:split>
</ul>
<br>Create the match regexp "m/\si[^\s]*\s([^\s]+)/mi" to match on any word starting with "i" and get the next word.<br>
<rx:regexp id="rx4">m/\si[^\s]*\s([^\s]+)/mi</rx:regexp>
<pre>
<rx:match id="match" regexp="rx4" text="test1">
  Match: <jsp:getProperty name="match" property="match"/>
    Parenthesized Group 1: <rx:group number="1"/>
    PreMatch: <jsp:getProperty name="match" property="preMatch"/>
    PostMatch: <jsp:getProperty name="match" property="postMatch"/>
</rx:match>
</pre>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -