Extracting matches from php regex

前端 未结 5 2085
深忆病人
深忆病人 2020-12-03 14:33

In perl regex we can extract the matched variables, ex below.

   # extract hours, minutes, seconds
   $time =~ /(\\d\\d):(\\d\\d):(\\d\\d)/; # match hh:mm         


        
5条回答
  •  生来不讨喜
    2020-12-03 14:40

    The simpler solution

    1. go to regex101.com
    2. Use the great documentation for creating and testing your regex (make sure you select PHP).
    3. In the TOOLS section click on code generation

    4. This is an example of what I got.

    $re = '/\#.*@hello\((?\w+),?(?.*)\).*/m';
    $str = ' Testing string
    # @hello(group_fields)
    # @hello(operator, arguments, more arguments)';
    
    preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
    
    // Print the entire match result
    var_dump($matches);
    

提交回复
热议问题