2013-03-13 90 views
0

我試圖用/在低於給定的數據一起提取字母之間的數據(我不想在多年的「s」和 - )。正則表達式提取標籤

football soccer/basketball 

1990s-1999s 

我在preg_match_all函數中使用/\D[a-zA-Z].*/s。它返回字母和數字(當在rubular.com中進行測試時,上述表達式可以工作,但在PHP程序中不會)。

回答

0
# ^([\D]+)$ 
# 
# Options: case insensitive;^and $ match at line breaks 
# 
# Assert position at the beginning of a line (at beginning of the string or after a line break character) «^» 
# Match the regular expression below and capture its match into backreference number 1 «([\D]+)» 
# Match a single character that is not a digit 0..9 «[\D]+» 
#  Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
# Assert position at the end of a line (at the end of the string or before a line break character) «$» 

preg_match_all('/^([\D]+)$/im', $subject, $result, PREG_PATTERN_ORDER); 
$result = $result[0]; 
+1

謝謝。我試過了,它的工作原理 – 2013-03-14 06:05:56

+0

@PritamRao很高興我能幫到你。請檢查它作爲接受的答案:) – 2013-03-14 08:45:57