2013-03-13 151 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