Matching user inputed regexp

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm using php and have a complicated task, so if someone can
understand it then please help me to solve it

The task is to make function, that will understand user-inputed regexp
and perfome some    actions with inputed regexp.

For example:
    'categories: ".*" -"foo"' means "all categories, but not 'foo'"
    'categories: "foo[a-b]*" ".*bar"'
   The regexp are not case-sensitive.

 A '-' (dash) preceeding a categoryname means "do not select this

 Here is the function that is ok for ".*" but not for ".* -foo":

function cheaker ($string ,$patterns) {
        $patterns_list = explode(" ", $patterns);
        foreach($patterns_list as $cs)
        $res = eregi($cs, $string, $regs);
     return $regs[0];

Re: Matching user inputed regexp

Quoted text here. Click to load it

Your input string is ".* -foo" or '".*" -"foo"'? because is the second
one, the explode return '.*' and '-foo' but is the first one it return
'.* -foo' and I think that you don't expect that.

Site Timeline