用于在标签之间提取数据的正则表达式

时间:2013-03-13 11:26:54

标签: php regex

我正在尝试在下面的给定数据中提取字母。(我不希望这些年份的's'以及 - )

football soccer/basketball

1990s-1999s

我在/\D[a-zA-Z].*/s函数中使用preg_match_all。它返回字母和数字。(在rubular.com中测试时,上面的表达式有效但在PHP程序中没有。)

1 个答案:

答案 0 :(得分: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];