From: Lucky Nl pargraph1 pargraph1 pargraph2 pargraph2 pargraph2 pargraph3 hello3 hell13 pargraph4 hello3 hell14 pargraph1 pargraph1 pargraph2 pargraph2 pargraph2 pargraph3 hello3 hell13 pargraph4 hello3 hell14 followed by any mixture of and space followed by ( |\s)*<\/p>/, ''
>
> (x|y) means match x or y, \s means match any whitespace character, and *
> means match it 0 or more times.
>
> To delete only the *last* paragraph if it is empty, then you can tweak
> it to:
>
> str.gsub! / ( |\s)*<\/p>\s*\z/, ''
>
> where \z matches the end of the string, and \s* allows 0 or more space
> characters, including newlines, to precede that.
>
> Once you're happy with that, then you can do another match and replace
> to change the final instance of "
( |\s)*<\/p>\s*\z/, '' ------------------------------------------------- str = "
pargraph1 pargraph1
pargraph2 pargraph2 pargraph2
pargraph3 hello3 hell13
pargraph4 hello3 hell14
" str = str.gsub! /
( |\s)*<\/p>\s*\z/, '' puts str --------------------------------- its returns below resule and it is fine. ----------------------------------------------
pargraph1 pargraph1
pargraph2 pargraph2 pargraph2
pargraph3 hello3 hell13
pargraph4 hello3 hell14
--------------------------------------------- But if i gave with littile modifiaction at endof line is enetered with charsdada ddsa
" str giving result nil -- Posted via http://www.ruby-forum.com/.