smeddles24
smeddles24

Reputation: 101

Compilation failed: nothing to repeat at offset 6

im not sure why this wont work... works perfectly in multiple regex checkers and testers. but when it comes to running it in PHP i get this error:

Warning: `preg_match()` [function.preg-match]: 
Compilation failed: nothing to repeat at offset 6 in /home/splose/public_html/index/index.php on line 49

im running this:

if(preg_match('[\\/^$.|?*+():<>]', $username)){}

Upvotes: 3

Views: 22354

Answers (2)

yanwen li
yanwen li

Reputation: 1

I think you should use regex expression with delimiters forward slashes (/)

// wrong pattern
$pattern = '[\\/^$.|?*+():<>]';
// right pattern
$pattern = '/[\\/^$.|?*+():<>]/';
if(preg_match($pattern, $username)){}

Upvotes: 0

Nonym
Nonym

Reputation: 6299

Perhaps you can try to delimit your pattern?:

if(preg_match('/[\\/^$.|?*+():<>]/', $username)){}

Taken directly from the PHP Docs :

Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

Upvotes: 6

Related Questions