1
0 10 2 012 11 12 12 test -f 13 x   xx
0 2   102 012 12 12 test -f 11 xxddd 22x
0 102 01 2  1    12   12 test -f 12 xxx

I need to find the number (between 1 and 5 digits) following the -f parameter using preg_match().

I'm a total bumpkin regarding PCRE matches.

I played arround with online preg testers and get stuck with \(.*)-f(\d{1,5})(.*)$\

1 Answer 1

1

Oh I didnt notice how close I got it:

\^.* -f (\d{1,4}).*$\

Array
(
    [0] =>     0 10 2 012 11 12 12 test -f 13 x   xx
    [1] => 13
)
Sign up to request clarification or add additional context in comments.

6 Comments

actually you only need -f\s+(\d+)\s
@GeraldSchneider I'm going to accept any working pattern posted by anyone if you feel free to answer yours...
I agree he doesn't need ^.*, but your \d+ will provide 1 or more digits, a number which could exceed 5 (he wants only digits up to 5).
usually when you parse a parameter you want the complete value until the next whitespace. reducing this to 5 just because you only have values with that length at the moment seems short sighted.
I agree, but I got the impression a string of numbers might follow the -f and he only wanted the first 5. Maybe I misunderstood the original question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.