EL and regular expression

Discussion in 'Java' started by francan, Feb 28, 2010.

  1. francan

    francan Guest

    I am trying to use a Regular Expression in Tomcat 6.0.20 with EL and
    its not working:
    <c:set var="info" value="joe2222" />
    Here are results = ${fn:replace(info,'\d+','')}<br><br>


    Error message -
    org.apache.jasper.JasperException: An exception occurred processing
    JSP page /jsp/reg2.jsp at line 14

    11:
    12:
    13: <c:set var="info" value="joe2222" />
    14: Here are results = ${fn:replace(info,'\d+','')}<br><br>


    Please advise.
     
    francan, Feb 28, 2010
    #1
    1. Advertising

  2. francan

    Lew Guest

    francan wrote:
    > I am trying to use a Regular Expression in Tomcat 6.0.20 with EL and
    > its not working:
    > <c:set var="info" value="joe2222" />
    > Here are results = ${fn:replace(info,'\d+','')}<br><br>
    >
    >
    > Error message -
    > org.apache.jasper.JasperException: An exception occurred processing
    > JSP page /jsp/reg2.jsp at line 14
    >
    > 11:
    > 12:
    > 13: <c:set var="info" value="joe2222" />
    > 14: Here are results = ${fn:replace(info,'\d+','')}<br><br>
    >
    >
    > Please advise.


    Find the exception that occurred. It will give you details. From the message
    it looks like a compiler error, but stopping at "an exception" gives too
    little detail.

    I suspect you have insufficient backslashes, and that the Java compiler is
    trying to parse '\d', which raises a compiler error.

    --
    Lew
     
    Lew, Feb 28, 2010
    #2
    1. Advertising

  3. francan

    francan Guest

    On Feb 28, 9:48 am, Lew <> wrote:
    > francan wrote:
    > > I am trying to use a Regular Expression in Tomcat 6.0.20 with EL and
    > > its not working:
    > > <c:set var="info" value="joe2222"  />
    > > Here are results = ${fn:replace(info,'\d+','')}<br><br>

    >
    > > Error message -
    > > org.apache.jasper.JasperException: An exception occurred processing
    > > JSP page /jsp/reg2.jsp at line 14

    >
    > > 11:
    > > 12:
    > > 13: <c:set var="info" value="joe2222"  />
    > > 14: Here are results = ${fn:replace(info,'\d+','')}<br><br>

    >
    > > Please advise.

    >
    > Find the exception that occurred.  It will give you details.  From the message
    > it looks like a compiler error, but stopping at "an exception" gives too
    > little detail.
    >
    > I suspect you have insufficient backslashes, and that the Java compiler is
    > trying to parse '\d', which raises a compiler error.
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -


    Thanks,

    I tried the below and it worked and got no error but it didnt
    substitute the value joe2222 for joe where the \d should replace the
    number:

    <c:set var="info" value="joe2222" />
    Here are results = ${fn:replace(info,'\\d+','')}

    Please advise.
     
    francan, Feb 28, 2010
    #3
  4. francan

    Lew Guest

    francan wrote:
    > I tried the below and it worked and got no error but it didnt
    > substitute the value joe2222 for joe where the \d should replace the
    > number:


    Don't you mean it didn't substitute the value "joe" for "joe2222"? (You
    substitute the new for the old; you replace the old with the new.)

    > <c:set var="info" value="joe2222" />
    > Here are results = ${fn:replace(info,'\\d+','')}


    Are you sure you have the right number of backslashes?

    It seems like you haven't researched how many layers translate strings,
    replacing doubled backslashes with single ones. Programming requires looking
    up documentation for the tools you use, in addition to just trying stuff to
    see what happens. The expression-language parser probably does that, the
    'fn:replace' tag probably does that and the Java parser certainly does that.
    I don't know the number myself off the top of my head (I'd have to look up the
    docs), but I suspect that there are three doublings going on.

    Even when you do just try stuff, you should track what you changed and what
    was the exact behavior you got, against the exact behavior you wanted.

    Speaking of which, your question provides very little data on which to base an
    answer. You hint at the behavior you want and you completely omit the
    behavior you got.

    You should follow the guidelines set forth in
    <http://sscce.org/>

    --
    Lew
     
    Lew, Feb 28, 2010
    #4
  5. francan

    Daniel Pitts Guest

    On 2/28/2010 8:23 AM, Lew wrote:
    > francan wrote:
    >> I tried the below and it worked and got no error but it didnt
    >> substitute the value joe2222 for joe where the \d should replace the
    >> number:

    >
    > Don't you mean it didn't substitute the value "joe" for "joe2222"? (You
    > substitute the new for the old; you replace the old with the new.)
    >
    >> <c:set var="info" value="joe2222" />
    >> Here are results = ${fn:replace(info,'\\d+','')}

    >
    > Are you sure you have the right number of backslashes?
    >
    > It seems like you haven't researched how many layers translate strings,
    > replacing doubled backslashes with single ones. Programming requires
    > looking up documentation for the tools you use, in addition to just
    > trying stuff to see what happens. The expression-language parser
    > probably does that, the 'fn:replace' tag probably does that and the Java
    > parser certainly does that. I don't know the number myself off the top
    > of my head (I'd have to look up the docs), but I suspect that there are
    > three doublings going on.

    Actually, I'm fairly certain that the string in JSP is the same as in
    Java, so "\\d+" would be correct. Now, the I wonder if fn:replace
    actually takes a regex. I don't think it does.
    >
    > Even when you do just try stuff, you should track what you changed and
    > what was the exact behavior you got, against the exact behavior you wanted.
    >
    > Speaking of which, your question provides very little data on which to
    > base an answer. You hint at the behavior you want and you completely
    > omit the behavior you got.
    >
    > You should follow the guidelines set forth in
    > <http://sscce.org/>
    >



    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Feb 28, 2010
    #5
  6. francan

    francan Guest

    On Feb 28, 11:23 am, Lew <> wrote:
    > francan wrote:
    > > I tried the below and it worked and got no error but it didnt
    > > substitute the value joe2222 for joe where the \d should replace the
    > > number:

    >
    > Don't you mean it didn't substitute the value "joe" for "joe2222"?  (You
    > substitute the new for the old; you replace the old with the new.)
    >
    > > <c:set var="info" value="joe2222"  />
    > > Here are results = ${fn:replace(info,'\\d+','')}

    >
    > Are you sure you have the right number of backslashes?
    >
    > It seems like you haven't researched how many layers translate strings,
    > replacing doubled backslashes with single ones.  Programming requires looking
    > up documentation for the tools you use, in addition to just trying stuff to
    > see what happens.  The expression-language parser probably does that, the
    > 'fn:replace' tag probably does that and the Java parser certainly does that.
    > I don't know the number myself off the top of my head (I'd have to look up the
    > docs), but I suspect that there are three doublings going on.
    >
    > Even when you do just try stuff, you should track what you changed and what
    > was the exact behavior you got, against the exact behavior you wanted.
    >
    > Speaking of which, your question provides very little data on which to base an
    > answer.  You hint at the behavior you want and you completely omit the
    > behavior you got.
    >
    > You should follow the guidelines set forth in
    > <http://sscce.org/>
    >
    > --
    > Lew


    I apologize if I was not clear in my post. I researched Custom
    Functions in JSP Expressions and created a function to make it work.
     
    francan, Mar 1, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    1
    Views:
    439
    Jürgen Exner
    Sep 25, 2004
  2. Replies:
    4
    Views:
    710
    Jürgen Exner
    Dec 7, 2004
  3. VSK
    Replies:
    2
    Views:
    2,303
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    851
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,970
    vforvikash
    Dec 29, 2008
Loading...

Share This Page