Regex break string based on and/or in a search concept

后端 未结 2 1628
甜味超标
甜味超标 2020-12-21 16:29

Hi I am trying to create regex expression and I am running into problems.

Basically this is what I have:

(.+?)(and|or)(.+?)

What I

2条回答
  •  一向
    一向 (楼主)
    2020-12-21 17:07

    Try this, but I used explode() method in PHP and not Regex.
    The input should have every user on a line, and without parenthesis (you can modify the code to remove the parenthesis), but at least this is the concept.

    ";
    
    //final array
    $result = array();
    
    //separate each line as element in an array
    $line = explode("\n",$string);
    
    //iterate through each line
    for($k=0; $k 1){
                $and[] = array();
                $lastId = count($and)-1;
                for($j=1; $j

    Output:

    Array
    (
        [0] => Array
            (
                [0] => user email ends with "@domain.com" 
                [1] =>  user name is "Bob" or user id is 5
                [2] => Array
                    (
                        [0] =>  user id is 5
                    )
    
            )
    
        [1] => Array
            (
                [0] => user email ends with "@domain.com" 
                [1] =>  user name is "Bob" or user id is 5
                [2] => Array
                    (
                        [0] =>  user id is 5
                    )
    
            )
    
    )
    

提交回复
热议问题