wp_spaces_regexp() WordPress Function

The wp_spaces_regexp() function is used to search for space characters in a given string. It is a Perl-compatible regular expression that can be used with the preg_match() function.

wp_spaces_regexp() #

Returns the regexp for common whitespace characters.


Description

By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp. This is designed to replace the PCRE \s sequence. In ticket #22692, that sequence was found to be unreliable due to random inclusion of the A0 byte.


Top ↑

Return

(string) The spaces regexp.


Top ↑

Source

File: wp-includes/formatting.php

function wp_spaces_regexp() {
	static $spaces = '';

	if ( empty( $spaces ) ) {
		/**
		 * Filters the regexp for common whitespace characters.
		 *
		 * This string is substituted for the \s sequence as needed in regular
		 * expressions. For websites not written in English, different characters
		 * may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0
		 * sequence may not be in use.
		 *
		 * @since 4.0.0
		 *
		 * @param string $spaces Regexp pattern for matching common whitespace characters.
		 */
		$spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0| ' );
	}

	return $spaces;
}


Top ↑

Changelog

Changelog
VersionDescription
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More