Documentation for ?: in regex?

后端 未结 6 720
日久生厌
日久生厌 2020-12-08 14:36

A while ago, I saw in regex (at least in PHP) you can make a capturing group not capture by prepending ?:.

Example

$str = \'big blue b         


        
6条回答
  •  隐瞒了意图╮
    2020-12-08 14:59

    I don't know how do this with ?:, but it is easy with simple loop:

    $regex = '/b(ig|all)/';
    $array = array(
        0 => array(0 => 'big', 1 => 'ball'),
        1 => array(0 => 'ig', 1 => 'all')
    );
    foreach ($array as $key => $row) {
        foreach ($row as $val) {
            if (!preg_match($regex, $val)) {
                unset($array[$key]);
            }
        }
    }
    print_r($array);
    

提交回复
热议问题