Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2006, 03:38 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expression escaping problem!

Hi all,

Well as you know characters such as '*' and '?' are reserved characters in regular expression so I suppose if I want to find the exact character (a '?' for example) in a string, I have to escape it with a backslash:

str=str.replaceAll("\?","a");

In the statement above, I need to replace all question marks with another character but it has a compile error:

Error(116,48): invalid escape character

to my surprise this code does the job while it should be interpreted as
one occurance of the '\' character or nothing at all:

str=str.replaceAll("\\?","a");


What's the problem? what's the general rule on escaping such characters?
 
Old June 14th, 2006, 07:16 PM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ya whenver u want to use the escape character in a regular expression u would have to necessarilly use "//" rather than using "/" . Since the later will not be recognised






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression repeat problem Indo77 ASP.NET 2.0 Basics 1 May 28th, 2008 06:45 AM
Regular expression problem keyvanjan ASP.NET 2.0 Basics 0 May 28th, 2007 12:19 PM
regular expression problem muki XSLT 2 January 11th, 2006 06:04 AM
Regular expression problem ghalebro PHP How-To 1 August 24th, 2004 08:10 AM
Regular Expression problem Mitch PHP How-To 2 May 14th, 2004 07:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.