2014-10-09 20 views

回答

0
"/\{\#(.*?)\#\}/g" 

而且學習正則表達式這裏http://regex101.com/


編輯:

你分享一些你的代碼,因爲它工作得很好。 這裏是正則表達式

http://regex101.com/r/aC1fT2/1

的測試,在這裏它是在行動:

~ 
⚡⚡⚡ more test.php; php test.php 
<?php 
//The source code 
    $pattern = "/\{\#(.*?)\#\}/"; 
    $test_string = 
    " 
     Lorem Ipsum is simply {#dummy#} text 
     of the printing and typesetting industry. 
     Lorem Ipsum has been the industry's {#standard#} dummy text 
     ever since the 1500s, 
     when an unknown printer took a galley of type 
     and scrambled it to make a type specimen book. 
     It has survived not only five centuries, 
     but also the leap into electronic typesetting, 
     remaining {#essentially unchanged#}. 
     It was popularised in the 1960s 
     with the release of Letraset sheets 
     containing Lorem Ipsum passages, 
     {#and more recently with desktop publishing software#} 
     like Aldus PageMaker including versions of Lorem Ipsum. 
    "; 
    preg_match_all($pattern, $test_string, $matches); 
    print_r($matches); 
?> 
... 
//The output 
Array 
(
    [0] => Array 
     (
      [0] => {#dummy#} 
      [1] => {#standard#} 
      [2] => {#essentially unchanged#} 
      [3] => {#and more recently with desktop publishing software#} 
     ) 

    [1] => Array 
     (
      [0] => dummy 
      [1] => standard 
      [2] => essentially unchanged 
      [3] => and more recently with desktop publishing software 
     ) 

) 
+0

'{# 名稱:測試 文件名:測試1 日期:123 作者日期:測試 #}' – 2014-10-10 16:12:09

+0

我甚至不... 不這行得通? – ehwas 2014-10-10 16:58:34