Unknown modifier 'v' when using preg_match() expression in regex [duplicate]
Asked Answered
M

1

1
        $regex = '/\b'.$keyword.'\b/i'; // case insensitive match
        if (preg_match($regex, $linkedin_html) == 0)
        {
            $this->_htmlValidationFailed++;
            continue;                
        }

When I use this code.. i get error as unknown modifier 'v'..

pls let me know what is the problem and help me rectify.

Morlee answered 9/7, 2012 at 11:40 Comment(5)
What is $keyword? Probably it have a /v and you need escape it.Sirree
it is some expression fetched from internet.Morlee
Try it: $regex = '/\b' . preg_quote($keyword) . '\b/i';Sirree
Impossible to answer unless you show us what the value of $keyword is. I suspect, like David, it contains something the REGEX engine is attempting to parse as REGEX grammar.Sequential
we cant know what $keyword is beforehand.. it is some required information fetched from internet while running the code.. and each time it varies for different input.Morlee
O
3
<?php
$keyword = preg_quote( $keyword, '/' );

$regex = '/\b'.$keyword.'\b/i'; // case insensitive match
if (preg_match($regex, $linkedin_html) == 0)
{
   $this->_htmlValidationFailed++;
   continue;                
}
Overprint answered 9/7, 2012 at 11:44 Comment(2)
thanks berry.. but now it says..Warning: preg_match(): Compilation failed: regular expression is too large at offset #######.Morlee
@NarenKarthik Well, I'm guessing that means that your regular expression is too large ;) If you're just testing for keywords, maybe a loop with strstr is a better fit than a regular expression?Overprint

© 2022 - 2024 — McMap. All rights reserved.