我正在尝试在下面的给定数据中提取字母和 / 。(我不希望多年来的“s”以及-)
football soccer/basketball
1990s-1999s
我 /\D[a-zA-Z].*/s
在preg_match_all
函数中使用。它返回字母和数字。(在 rubular.com 中进行测试时,上述表达式有效,但在 PHP 程序中无效)。
# ^([\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];