0

我正在尝试在下面的给定数据中提取字母和 / 。(我不希望多年来的“s”以及-)

football soccer/basketball

1990s-1999s

/\D[a-zA-Z].*/spreg_match_all函数中使用。它返回字母和数字。(在 rubular.com 中进行测试时,上述表达式有效,但在 PHP 程序中无效)。

4

1 回答 1

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];
于 2013-03-13T11:46:08.973 回答