Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MYSQL REGEXP (Special Characters)

Status
Not open for further replies.

altendew

Programmer
Mar 29, 2005
154
US
I am currently using PHP and MYSQL, and I would like to know all of the characters I have to denote with a backslash \.

I know perl and php are ". \ + * ? [ ^ ] $ ( ) { } = ! < > | :"

What would MySQL be?
 
I just made my own thing..

Code:
function mySqlParse($string)
{
	// Load special characters
	$special = '-<>.+*$^!()\[\]{}';

	// Remove beginning and ending spaces from string.
	$string = trim($string);

	// Backslash Special Characters
	$string = preg_replace('/(\\\\)/', '\\\\\\\\', $string);
	$string = preg_replace('/(['.$special.'])/', '\\\\\\\\\1', $string);

	// Fix Double Spaces
	$string = preg_replace('/\s+/', '[[:space:]]+', $string);

	// Insert Word Boundaries	
	$string = '(^|[[:<:]]|[[:space:]])'.$string.'([[:space:]]|[[:>:]]|$)';

	return $string;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top