PHP Regexp yardım

3 Cevap php

Ben bu ifade ayıklamak niyetinde ne bir tanıtıcı almak gibi olamaz:

preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match);

$match bir dizi ise $line, bir metin dosyasından bir çizgidir

3 Cevap

İşte bir açıklama:

^               # match the beginning of the input
(?:             # start non-capture group 1 
  [\s*]*?       #   match any character from the set {'0x09'..'0x0D', '0x20', '*'} and repeat it zero or more times, reluctantly
  @             #   match the character '@'
  (             #   start capture group 1
    [^*/]+?     #     match any character from the set {'0x00'..')', '+'..'.', '0'..'ÿ'} and repeat it one or more times, reluctantly
  )             #   end capture group 1
  \s            #   match a whitespace character: [ \t\n\x0B\f\r]
  (             #   start capture group 2
    .+          #     match any character except line breaks and repeat it one or more times
  )             #   end capture group 2
)               # end capture group 1

* * *@abc asd: regex maç olacağını bir örnek dize bu

Edit:

Yukarıdaki açıklama oluşturmak için kullanılan çözümleyici bir beta sürümünü yayımladı ettik. Burada indirebilirsiniz: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html

Muhtemelen (ilk ve son satır hariç) bu gibi açıklama bloğu hatları yakalamak için çalışır:

/**
 * @param  $arg1 etc...
 * @return bool etc...
 */

Bu, form dizileri eşleşir

** *  ***@anything_that_is_not_an_asterisk_nor_a_slash   anything else

$match[1] "anything_that_is_not_an_asterisk_nor_a_slash", ilk önce, alanı, $match[2] ihtiva " anything else" içerir.