Php 使用正则表达式匹配字符串

Php 使用正则表达式匹配字符串,php,regex,Php,Regex,我有一个字符串,看起来像这样: 089 / 23249841noch not deposited 我想从字符串中提取以下部分: 089 / 23249841 如何使用PHP和正则表达式实现这一点?假设要匹配第一个字母之前的所有内容 preg_match("/(^[^a-z]+)/i", "089 / 23249841noch not deposited", $match) $match将包含 Array ( [0] => 089 / 23249841 [1] =>

我有一个字符串,看起来像这样:

089 / 23249841noch not deposited
我想从字符串中提取以下部分:

089 / 23249841

如何使用PHP和正则表达式实现这一点?

假设要匹配第一个字母之前的所有内容

preg_match("/(^[^a-z]+)/i", "089 / 23249841noch not deposited", $match)
$match
将包含

Array
(
    [0] => 089 / 23249841
    [1] => 089 / 23249841
)

仅举一个例子,为它编写一个合适的正则表达式有点棘手。然而,这一点应该是可行的:

[0-9 /]+
或者,在完整的php中:

$str = '089 / 23249841noch not deposited';
$matches = array();
if (preg_match('[0-9 /]+', $str, $matches)) {
    var_dump($matches);
}

欢迎您@MubinKhalid,很高兴它按您希望的那样工作:)