Java String.replaceAll regex

Posted by atomsfat on Stack Overflow See other posts from Stack Overflow or by atomsfat
Published on 2010-04-08T17:35:10Z Indexed on 2010/04/08 17:43 UTC
Read the original article Hit count: 352

Filed under:
|
|

I want to replace the first context of

web/style/clients.html

with the java String.replaceFirst method so I can get:

${pageContext.request.contextPath}/style/clients.html

I tried

String test =  "web/style/clients.html".replaceFirst("^.*?/", "hello/");

And this give me:

hello/style/clients.html

but when I do

 String test =  "web/style/clients.html".replaceFirst("^.*?/", "${pageContext.request.contextPath}/");

gives me

java.lang.IllegalArgumentException: Illegal group reference

© Stack Overflow or respective owner

Related posts about java

Related posts about regex