• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regexp : escape sequences in string

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

Escape Sequences (JLS.)
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic