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

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -

javascript - three.js lot of meshes optimization -