Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help with regular experssion in Java and escape characters

Posted on 2004-10-11
9
Medium Priority
?
275 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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