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.

https://regex101.com/r/mt0ie7/24


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -