Solved

Need help with regular experssion in Java and escape characters

Posted on 2004-10-11
9
262 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 167 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 167 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 166 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

729 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