Solved

Need help with regular experssion in Java and escape characters

Posted on 2004-10-11
9
244 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 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