tribe_unfenced_regex( string $regex )

Removes fence characters and modifiers from a regular expression string.

Use this to go from a PCRE-format regex (PHP) to one SQL can understand.


Parameters #

$regex

(string) (Required) The input regular expression string.


Top ↑

Return #

(string) The un-fenced regular expression string.


Top ↑

Source #

File: src/functions/utils.php

	function tribe_unfenced_regex( $regex ) {
		if ( ! is_string( $regex ) ) {
			return $regex;
		}

		$str_fence   = $regex[0];
		// Let's pick a fence char the string itself is not using.
		$fence_char = '~' === $str_fence ? '#' : '~';
		$pattern = $fence_char
		           . preg_quote( $str_fence, $fence_char ) // the opening fence
		           . '(.*)' // keep anything after the opening fence, group 1
		           . preg_quote( $str_fence, $fence_char ) // the closing fence
		           . '.*' // any modifier after the closing fence
		           . $fence_char;

		return preg_replace( $pattern, '$1', $regex );
	}

Top ↑

Changelog #

Changelog
Version Description
4.9.5 Introduced.