3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); static $text1 = ' Пароль: 0936 Спишется 1241р. Перевод на счет 410012124208089 '; static $text2 = ' Пароль: 3042 Спишется 1240,21р. Перевод на счет 410012124208089 '; static $text3 = ' Пароль: 3042 Спишется 1240,21 руб Перевод на счет 410012124208089 '; function parse(string $text): array { $count = preg_match_all(/** @lang RegExp */ '/ (?: # самое простое — кошелёк получателя. Считаем, что он 15 символов (?<address>\d{15}) # дальше самое сложное — сумма перевода. Может быть целым или с разделителем копеек, в этом и сложность # так как может быть целым, то нам нужно её отличить от кода подтверждения |(?: (?<sum> \d+ (?:[,.]{1}\d+|) ) # будем считать, что после суммы будет написана валюта. Иначе не угадать что — код, а что — сумма. # допустим, что может быть слитно или через пробелы # допустим, что по-английски или по-русски, с маленькой или с большой буквы (?i:\s*[рr]) ) # дальше опять просто — код подтверждения. Просто целое число |(?<code>\d+) ) /x', $text, $matches, PREG_SET_ORDER); var_dump($matches); die; if ($count !== 3) { throw new RuntimeException('Всё пропало, нужно писать новую регулярку'); } $sum = 0; $code = 0; $address = 0; for ($i = 0; $i < 3; $i++) { [$tempSum, $tempCode, $tempAddress] = [$matches['sum'][$i], $matches['code'][$i], $matches['address'][$i]]; if ($tempSum) { $sum = $tempSum; } if ($tempCode) { $code = $tempCode; } if ($tempAddress) { $address = $tempAddress; } } return compact('code', 'sum', 'address'); } echo $text1 . PHP_EOL; $result = parse($text1); var_dump($result); echo $text2 . PHP_EOL; $result = parse($text2); var_dump($result); echo $text3 . PHP_EOL; $result = parse($text3); var_dump($result);
Output for git.master, git.master_jit, rfc.property-hooks
Пароль: 0936 Спишется 1241р. Перевод на счет 410012124208089 array(3) { [0]=> array(7) { [0]=> string(4) "0936" ["address"]=> string(0) "" [1]=> string(0) "" ["sum"]=> string(0) "" [2]=> string(0) "" ["code"]=> string(4) "0936" [3]=> string(4) "0936" } [1]=> array(5) { [0]=> string(5) "1241�" ["address"]=> string(0) "" [1]=> string(0) "" ["sum"]=> string(4) "1241" [2]=> string(4) "1241" } [2]=> array(3) { [0]=> string(15) "410012124208089" ["address"]=> string(15) "410012124208089" [1]=> string(15) "410012124208089" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.07 ms | 402 KiB | 8 Q