This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes PatternSyntaxException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PatternSyntaxException" Watch "PatternSyntaxException" New topic
Author

PatternSyntaxException

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
I wrote this program, it throws a patternsyntaxexception, not sure why
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3605
    
  14

What are you trying to replace? "\\" is not a valid regex.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

"\\" is a String with one character, \. That happens to be an escape character in regular expressions as well. That means that you will need to escape it in your regex. That turns the regex into \\, so the String becomes "\\\\".

Or you simply use String.replace(). Since Java 5.0 or 6 it has been overloaded to take any CharSequence, which is an interface implemented by String. It behaves a bit like replaceAll except it takes a literal String, not a regex.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: PatternSyntaxException
 
Similar Threads
Trying to create an arraylist of objects based on information from a text file
Polimorphism x Casting
nullpointerexception
Hot to deal with OutOfMemoryError
Inheritance doubt