Reputation: 1305
I am new to regexp in php. I am just trying to do a simple preg_match on two strings. Here is my code:
$pattern = '\\w*'.strtolower($CK);
if(preg_match($pattern, $rowName, $matches) == true)
{
echo 'true';
}
But I keep getting the error:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/daskon/public_html/reflexInvestor_dev/php/rss_functions.php on line 319
I imagine it's because I need to put something after the pattern, but I can;t seme to find what that is. When I try the same pattern in a regexp tester, it works fine.
Upvotes: 2
Views: 708
Reputation: 165261
You need to wrap the pattern in delimiting characters (I like to use #
since I rarely need them inside of the regex):
if (preg_match('#' . $pattern . '#', $rowName, $matches)) {
(You also don't need the == true
, it's redundant since that's what the if does anyway internally...)
Upvotes: 2
Reputation: 175585
You need to wrap the pattern in a delimiter that marks the beginning and end. Any "non-alphanumeric, non-backslash, non-whitespace" character works. /
is very common, so:
$pattern = '/\\w*' . strtolower($CK) . '/';
The reason for the delimiter is you can include pattern modifiers in the pattern, but they appear after the delimiter
Upvotes: 3