Regular Expressions 101

Community Patterns

Trim

1

Regular Expression
PCRE (PHP <7.3)

/
^[ \s\0\x0B]+|[ \s\0\x0B]+$
/
gm

Description

Popular trim Regular Expression.

Matches whitespace characters at the beginning and end of a string.

Check out the usage examples in the test string to see how you can implement it into your own code.

Submitted by Shawn G. - 10 years ago