java - Trimming trailing whitespace from every line in a multi-line string using replaceAll -


Please explain why in this expression, the replacement occurs only once at the end of the string.

  "1 \ n3 \ n5" .replaceAll ("+ $", "x") // = & gt; According to "1 \ n3 \ n5x"  

, $ must match the end of a row, and \ z input Matches the end of the string.

My goal is to replace the last position of the white space at the end of each row in the string. "x" There is only one way to reflect the replacement that is being replaced.

I think a regular expression and String.replace All should be able to do this. If changing is not able to do all of this operation , please suggest a brief option.

To change the paragraph spacing of each line, you must enter m ( Multi-line) modifier.

  "1 \ n3 \ n5". ReplaceAll ("(? M =" $ "," x ") // = & gt; "1x \ n3x \ n5x"  

Note : This modifier matches ^ and $ Is the beginning and end of each line


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -