regex - Remove all spaces from lines starting with specific word -


using regex find/replace in notepadd++ how can remove spaces line if line starts 'chapter'?

example text:

chapter b c once upon time. 

what want end with:

chapterabc once upon time. 

incorrect code like:

(?<=chapter)( )(?<=\r\n) 

so 'chapter' needs stay , search should stop @ first line break.

you may use \g based regex match line starts chapter , match consecutive non-whitespace , whitespace chunks linebreak while omitting matched non-whitespace chunks , removing horizontal whitespace:

(?:^chapter|(?!^)\g)\s*\k\h+ 

details:

  • (?:^chapter|(?!^)\g) - chapter @ start of line (^chapter) or (|) end of previous successful match ((?!^)\g, \g can match start of line, use retricting negative lookahead.)
  • \s* - 0 or more non-whitespace symbols
  • \k - match reset operator forcing regex engine omit text matched far (thus, not remove chapter or of non-whitespace chunks)
  • \h+ - horizontal whitespace (1 or more occurrences) only

enter image description here


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -