Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2015-10-21 09:22
Flavor·JavaScript

/
(^\s+|\s+$)
/
gm
Open regex in editor

Description

Remove whitespace before and after the string. Use g for trimming before and after Use m for trimming each line of a multiline string individually.

Code: ' test '.replace( /(^\s+|\s+$)/gm, '' );

Submitted by KevinV