English 中文(简体)
定期发表在《联合公报》中删除特殊性的言论
原标题:Regular expression to remove special characters in JSTL tags

我正在准备春天申请,在IJSPX网页上,需要动态地从财产页上装出某些价值,并用各种选择标记将其 as倒。 我需要用相同的案文来说明各种选择的价值,并表明各种选择的价值,但需要删除所有的特殊性。

例如,如果价值是母异构体,那么我就需要

<option value="MaternalUncle">Maternal Uncle</option>

我正在得到的东西。

<option value="Maternal Uncle">Maternal Uncle</option>

有2份申请可使用该网页,哪些财产可装上该页面。 如果我对图1的负荷值进行适当展示,则表1中的最后价值是其他数值,没有特殊性。 对图2而言,它并不珍视那些最后价值为“母异构体”的白色空间。 代码中的复制物是具有从财产档案中载取的价值的ArrayList。 我的守则是:

<select name="person" id="person">
      <option value="na">Select the relationship</option>
  <c:forEach items="${repOptions}" var="repOption">
       <option value="${fn:replace(repOption,  [^A-Za-z] ,  )}">${repOption}</option>
  </c:forEach>
</select>

第一次评估将白空间移走,因为这一价值在9个名单中是第4个。 大约2 ,这是最后价值,没有发挥作用。 如果我把“母子”当作头一种财产,那么这项工作就会被罚款,但要求最后选择。

 <option value="${fn:replace(repOption,    ,  )}">

从事白天工作,但像兄弟/修女这样的价值观,因此,我需要删除,因此,我也正在使用reg。

最佳回答

The JSTL fn:replace(,不使用固定的代谢。 它只是一个准确的char-逐-char,完全像 <<<>

劳动和社会保障部没有为此提供另外一种职业资格。 您仅可担任EL职能,出席以下会议的代表:>:String#replace All(All)(/a>。

E.g.

package com.example;

public final class Functions {

     private Functions() {
         //
     }

     public static String replaceAll(String string, String pattern, String replacement) {
         return string.replaceAll(pattern, replacement);
     }

}

贵国在<代码>/WEB-INF/Functions.tld上登记如下:

<?xml version="1.0" encoding="UTF-8" ?>
<taglib 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
    version="2.1">

    <display-name>Custom Functions</display-name>    
    <tlib-version>1.0</tlib-version>
    <uri>http://example.com/functions</uri>

    <function>
        <name>replaceAll</name>
        <function-class>com.example.Functions</function-class>
        <function-signature>java.lang.String replaceAll(java.lang.String, java.lang.String, java.lang.String)</function-signature>
    </function>
</taglib>

最后使用如下:

<%@taglib uri="http://example.com/functions" prefix="f" %>

...

${f:replaceAll(repOption,  [^A-Za-z] ,   )}

或者,如果你已经在Serlet 3.0 /EL 2.2或新版(Tomcat 7或newer)上重新启用,那么EL开始支持以论据援引方法,简单地直接援引String#replaceAll( )。

${repOption.replaceAll( [^A-Za-z] ,   )}

See also:

问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签