aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regexp : escape sequences in string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regexp : escape sequences in string " Watch "regexp : escape sequences in string " New topic
Author

regexp : escape sequences in string

Men Gumani
Ranch Hand

Joined: Apr 01, 2009
Posts: 31
Hi all,
How can I tell if the compiler will complain about a certain escape sequence, e.g. why "\"" is known to the compiler whereas "\." is not? Does it make any difference if compiler knows it?
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Yes, there is a definite set of escape sequences. You can look at them here:

Escape Sequences (JLS.)


All code in my posts, unless a source is explicitly mentioned, is my own.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
Because a double quote is used to represent a string. How would the compiler know where to end the string? A period doesn't cause any problems.
Hesham Abo El-Magd
Greenhorn

Joined: Aug 21, 2008
Posts: 9
when you would like to escape a certain special character you use "\" followed by the that character but if you like to escape the" \" you use" \\ "and "." you use "\\."


SCJP 5.0
NetBeans Platform Certified Associate .
Bachelor of Computer Science .
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Hesham Abo El-Magd wrote:when you would like to escape a certain special character you use "\" followed by the that character but if you like to escape the" \" you use" \\ "and "." you use "\\."

Using "\\." doesn't result in ".", it results in "\.". Also, escape processing happens in one run. In other words, "\\307" will result in "\307", whereas "\307" results in "C".
Hesham Abo El-Magd
Greenhorn

Joined: Aug 21, 2008
Posts: 9
actually compiler see this "\." as an illegal Java escape sequence . and about that "\\." compiler or regex see this as dot not as metacharacter in your pattern expression .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regexp : escape sequences in string