conditional preg_match in PHP
tried /[^fF\d+\s+]?[AF]?[\s+]?(\d+(\.\d{1,2})?-\d+(\.\d{1,2})?)/
want to match:
AF11-16
AF 11-16
11-16
16.5-100
but do not match:
f3.5-5.6
F3.5-5.6
f 3.5-5.6
F 3.5-5.6
want to extract the focal开发者_高级运维 length range as result, like 11-16
do not know how to use conditional subpattern, any idea? thx!
^(?:af)?\s?([\d.]+)-([\d.]+)$
This one works for your dataset, as you can see here.
Instead of
\d+
use
\d{2,}
which will matches two or more digits.
/[^fF\d+\s+]?[AF]?[\s+]?(\d{2,}(\.\d{1,2})?-\d{2,}(\.\d{1,2})?)/
精彩评论