Link to home
Start Free TrialLog in
Avatar of polkadot
polkadot

asked on

Need help with regular experssion in Java and escape characters

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

String regex = "\\{x=0\\}";
Avatar of polkadot
polkadot

ASKER

and about spaces? see question
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
\s Matches any white space character including space, tab, form-feed, and so on.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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

>>The second comment was given in split seconds of time.

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