2013年10月30日星期三

Help a regex

I now have a code, but there are all the comments have been garbled. . .
I want to delete all comments , it should be how to write ?
the way to learn a science regular . .
notes have
/ ** ggg * /
/ / gg
two kinds
------ Solution ---------------------------------- ----------
public static void regexReplace () {
String str = "gewgew / ** gegew * / gwegew / / gwegew \ n";
System.out.println (str);
String regex = "/ \ \ * \ \ *. *? \ \ * / | / /. *? \ n";
str = str.replaceAll (regex, "");
System.out.println (str);
}
test no problem. .
------ For reference only -------------------------------------- -
can help explain it ? Come on friends
------ For reference only ------------------------------------ ---
feeling is your eclipse encoding settings and engineering coding inconsistencies caused. If the program in which there are other Chinese except for comments , it may also be garbled ! You can try to turn the next coding can resume correctly
------ For reference only ---------------------------- -----------
String str = "hello / * go to * / world";
tried to delete this it ?
------ For reference only -------------------------------------- -
String regex = "/ \ \ * \ \ *. *? \ \ * / | / /. *? \ n";

\ \ is the escape character , because * is a special character , you need to escape . . .

. *? was matched to the first qualifying on end. Here's the end condition is \ \ * / that is encountered * / .

| yes or meaning. . .
look / / at the beginning , in the middle no matter what , until the end of the line . . .

find these all meet the criteria, replaced with " " , it means deleted
------ For reference only ---------------- -----------------------

plus one | regularity conditions on it. .
seemingly conditions which did not say there
/ ** / type

------ For reference only ---------------------------------- -----

plus one | regularity conditions on it. .   
seemingly conditions which did not say there   
/ ** / type   
 
remove a \ \ *, String regex = "/ \ \ *. *? \ \ * / | / /. *? \ n";
------ For reference only - --------------------------------------

have tried this forms no : String str = "hello / * This is \ n a test case * / world";
Because, I'm not sure the java language . matches newline
------ For reference only -------------------- -------------------

have not tried this form : String str = "hello / * This is ; \ n a test case * / world ";   
Because, I'm not sure the java language . matches newline  
front plus (? s) can ignore the newline . . . .

没有评论:

发表评论