Page 1 of 1

About Question enthuware.ocpjp.v7.2.1426 :

Posted: Wed Feb 20, 2013 4:51 pm
by ETS User
Do we need to escape "\\d\\d"?

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Wed Feb 20, 2013 5:39 pm
by admin
No, the additional '\' is required only when you are using a special character within a string in the code. For example, "\\t is for tab". If you don't put \\ here, you will get " is for tab".

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Fri Mar 13, 2015 2:31 am
by ArnobDe
0 12 followed by 3d dc 2a b2 3 [matching 2 characters at a time] then please explain 9 23 :?:

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Fri Mar 13, 2015 5:37 am
by admin
Not sure what is your question. The pattern matches 2 consecutive digits not just any two characters.

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Fri Jan 06, 2017 5:12 am
by jagoneye
admin wrote:No, the additional '\' is required only when you are using a special character within a string in the code. For example, "\\t is for tab". If you don't put \\ here, you will get " is for tab".
What? It runs fine with a single '\' in this statement for example:

Code: Select all

System.out.println("\t yosha");
Output:

Code: Select all

	 yosha
you can use single '\' for special characters like
b t n r " ' \.
Only for regex you need to escape the '\' because '\s' is required for example but in
Java String you need to escape '\' with '\' hence the String will be '\\s'.
Hope I'm not wrong. :)

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Fri Jan 06, 2017 8:51 am
by admin
You are right \\ is only required in a string for regex patterns because you want to let \ be a part of the regex.
thank you for your feedback!

Re: About Question enthuware.ocpjp.v7.2.1426 :

Posted: Fri Jan 06, 2017 8:56 am
by jagoneye
admin wrote:You are right \\ is only required in a string for regex patterns because you want to let \ be a part of the regex.
thank you for your feedback!
You are welcome. :)