?
Solved

Need help with regular experssion in Java and escape characters

Posted on 2004-10-11
9
Medium Priority
?
267 Views
Last Modified: 2010-08-05
I want to remove the string "{x=0}" from text. Not sure how to represent {

String text;
String regex = "/{"; //this gives compile error: illegal escape character
text = text.replaceAll(regex, "");

if I use the other \{ it will run but gives me run time error about illegal escape sequence ..

aslo how do I use this method to replace a sequence of spaces and tabs from text? what would be the regex?
0
Comment
Question by:polkadot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12280283
String regex = "\\{x=0\\}";
0
 

Author Comment

by:polkadot
ID: 12280307
and about spaces? see question
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 668 total points
ID: 12280345
>>what would be the regex?

Missed that sorry - well it would depend on the exact sequence. If it's any range of contiguous whitespace, try

s = s.replaceAll("\\s+", "");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 668 total points
ID: 12280351
\\s
0
 
LVL 3

Expert Comment

by:yellowjetski
ID: 12280356
\s Matches any white space character including space, tab, form-feed, and so on.
0
 
LVL 3

Accepted Solution

by:
yellowjetski earned 664 total points
ID: 12280367
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12284877
polkadot - i'm confused by your treatment of this question. I answered both the main question here and the 'subquestion' yet

a. the comment marked as the accepted answer relates merely to syntax in a different language.

and

b. The other comment marked as 'assisted' repeats info i'd already given.

 Why?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12284931
CEHJ ,

The second comment was given in split seconds of time. And I am late.
If you think, you deserve the points. no problem. I am ready to give the points.
And finally it's  polkadot's decision. If he/she is willing to reopen and reassign the points

Regards
Sudhakar

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12284937
>>The second comment was given in split seconds of time.

Don't worry - i'm not blaming you sudhakar
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question