Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regexp : escape sequences in string

 
Men Gumani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there is a definite set of escape sequences. You can look at them here:

Escape Sequences (JLS.)
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "\\."
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic