java - How to delete a string only containing a word using regex? -
1 line: "*hello: " 2 line: "*hello: " 3 line: "*hello: person answered" would delete line 1 , 2 entirely, want keep line 3, without becoming:
"*hello:person answered" tried:
line = line.replaceall("*hello:(\\s*)","");
you can
line = line.replaceall("^\\*hello:\\s*$",""); or
line = line.replaceall("\\*hello:\\s*(?!.*\\w)",""); this should you.see demo.
Comments
Post a Comment