Solved

trying to remove c like comments with regex. i am sure it is a escape thing

Posted on 2008-06-23
4
179 Views
Last Modified: 2010-03-30
hello,
i am parsing a file and have a line that looks like
body{/* 1 */
i am trying to replace /*something*/ with "" so it would look like
body{

i tried
nodeStr = nodeStr.replaceAll("\\/*/?\\w++[^>]*+*\\/", "");

thanks for any help
Randy

0
Comment
Question by:paries
[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
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21852572
Its the * you want escape \*, it has special meaning in a regexp
0
 
LVL 7

Expert Comment

by:humanonomics
ID: 21852585
I presume you want to get rid of the complete comment including the contents.
try the following regex it will work.

nodeStr =nodeStr.replaceAll("[(/\\*\\S\\s\\*/)]", "");
0
 
LVL 7

Expert Comment

by:humanonomics
ID: 21852587
Oops sorry, ignore my previouse comment, that will erase everything, need to work more on it.
0
 
LVL 7

Accepted Solution

by:
humanonomics earned 500 total points
ID: 21852661
Try this one.

String nodeStr = trial.replaceAll("/\\*?[^>]+\\*/", "");
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

734 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