I'm having hard time trying to figure out regular expression that will extract 4 digits long number after certain word as full match.
Here is the text:
FV 7017 FOR SOMETHING 1076,33 USD.
and here is my regular expression to extract the 4 digits number:
/FV (\d{4,})/
That will result in:
Full match = `FV 7017`
Group 1 match = `7017`
Is it possible to exclude that "FV" word using regex to have that result as full match?
4 steps faster than a positive lookbehind, is to use \K
to restart the fullstring match.
/FV \K\d{4}/
PHP Implementation:
$string='FV 7017 FOR SOMETHING 1076,33 USD.';
echo preg_match('/FV \K\d{4}/',$string,$out)?$out[0]:'fail';
// output: 7017