JS: ' hello world '.replace(/^\s+|\s+$/g, '')
Py: re.sub(r'^\s+|\s+$', '', ' hello world ')
output
"hello world"
Note Equivalent to str.trim() in JS and str.strip() in Python. The regex version is useful when you also want to normalize internal whitespace: replace /\s+/g with ' ' after trimming.