Regular expressions jsp

I am trying to replace encoded http%3A%2F%2F with http:// in a string using regular expressions in a jsp...
Not much luck so far, it replaces the first occurrence but the second one is replaced OK, but ":" column is missing...
So the second occurrence became http//.
I actually don't need to replace the second occurrence, but only the first one.
My string always starts with http%3A%2F%2F.
What is the correct regex and replacement for this using regular expressions?
 Basically i need
http%3A%2F%2F become http:// only ones.
Thank you.
olenadmytrenkoAsked:
Who is Participating?
 
ZvonkoSystems architectCommented:
The normal behaviour is that repalce methods do replace oncce when NOT searching by RegExp.
So look for your <cas:replace what the contepart for regex= keyword is and you are done. Then you need something like this:

<cas:replace  search="http%3A%2F%2F" replacement="http://"/>

I did not found cas tag library description, but I assume it is something like:

<cas:replace  if="http%3A%2F%2F" replacement="http://" />

0
 
objectsCommented:
why don't you just decode the string?
0
 
objectsCommented:
if u want to use regexp try something like:

s = s.replaceAll("%3A", ":").replaceAll("%2F", "/");
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ksivananthCommented:
I am not sure if I understand your problem clearly...

String str = "http%3A%2F%2F"
str = str.replaceAll( str, "http://" )
0
 
ksivananthCommented:
yes, as objects said, decoding the string would resolve the problem and that is the standard way too!
0
 
olenadmytrenkoAuthor Commented:
The thing is that string must be encoded for some rating purposes.
I need to decode  http:// because if the string starts with encoded value
which is used in an ancor (a href=""), then the whole url is treated as  relative..
So if http:// is http%3A%2F%2F, then there is http://localhost:8080 is appended infront of my  encoded http://

Basically  I have a custom tag which can replace substrings based on regular expressions, like
<cas:replace regex="http%3A%2F%2F" replacement="http://"/>
so I thought I'll use it, it does everything ok, except I am not sure about the string in replacement part, coz it accpets regular expressions and I am rubbish with them.
If it all sounds too complicated then I could use just java string relpace....
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.