{ordinary|normal|regular|standard}
以上用正则表达式写出,花括号中间内容只能是字母,空格,|,主要是查出两边的花括号{};
请问这种表达式怎么写?

解决方案 »

  1.   

     very ordinary-looking women{regular|standard}wired phenomenon in the job{et|etplace}but in most of
     还有以上
    }wired phenomenon in the job{
    }……{  中间内容不能有花括号
    这个一段的正则又该怎么写?
      

  2.   

    <?php
    $str = 'asdfefefefefef{ordinary|normal|regular|standard}';
    $patten = '/(\{[ a-z|]+\})/i';
    preg_match_all($patten,$str,$matches);
    print_r($matches);
      

  3.   

    <?php
    $str = 'very ordinary-looking women{regular|standard}wired phenomenon in the job{et|etplace}but in most of';
    $patten = '/\}([^{]+)\{/i';
    preg_match_all($patten,$str,$matches);
    print_r($matches);
      

  4.   


    $STR = 'very ordinary-looking women{regular|standard}wired phenomenon in the job{et|etplace}but in most of';
    preg_match_all('/\{[a-z\s|]+\}/isU', $STR, $matches);
    print_r($matches);
    /**
    输出结果:
    Array ( [0] => Array ( [0] => {regular|standard} [1] => {et|etplace} ) ) 
    */
      

  5.   


    不是两遍。
    匹配的结果保存在$matches[1]中