2

I'm writing a tool -for private use- that reads a string. The containing string is full url encoded. Normaly I use this site for decode or encode a string. So I took a look at the source code. In the source of this, I found two regexpressions:

.replace(/'/g,"%27").replace(/"/g,"%22")

and

.replace(/\+/g,  " ")

I think the first does replace all ' to %27 and " to %22. Is that right? If not, what is the pendant in Java?

At second statement, I have no idea what does it mean and do. Can some explain it and what is the pendant Java?

I'm still an absolute beginner with regexpressions, so I hope the community here can help.

Thanks.

2 Answers 2

6

You are right about the first statement.

As for the second statement, it is replacing plus "+" signs by spaces " " (%20).

It is written as /\+/because plus "+" is a special character and has to be escaped.

Sign up to request clarification or add additional context in comments.

Comments

4

You can use the String.replaceAll method:

input.replaceAll("'", "%27").replaceAll("\"", "%22");

And

input.replaceAll("\\+", " ");

1 Comment

Thanks for your answer to. Because I could mark only one answer, you got +1 from me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.