Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 PHP 正则表达式。我试过这段代码:
$regex = "c:(.+),"; $input = "otherStuff094322f98c:THIS,OtherStuffHeree129j12dls"; $match = Array(); preg_match_all($regex, $input, $match);
它应该THIS从$input. 但它返回一个空数组。我究竟做错了什么?
THIS
$input
我认为您需要斜杠才能使正则表达式正常工作。
并且 using.+也将匹配逗号后面的所有内容,这是您不想要的。使用.+?或[^,]+
.+
.+?
[^,]+
$regex = "/c:(.+?),/";
或者
$regex = "/c:([^,]+),/";