0

以下の特定のデータで / とともに文字を抽出しようとしています。

football soccer/basketball

1990s-1999s

関数で使用 /\D[a-zA-Z].*/sしていpreg_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 に答える