The regex from your sed command going to remove single spaces globally from your string anywhere it finds a space. Try stripping repeating whitespace from beginning of line and end of line.
| makeresults | eval A=" leading and trailing spaces " , a_len=len(A) | rex field=A mode=sed "s/^\s+//g" | rex field=A mode=sed "s/\s+$//g" | eval new_len=len(A)
but why rex is adding spaces to the value retrieved ?
what should i change in rex to avoid the space, as if i have 5-10 fields extracted, each will have the trailing and leading space to their values.