0

I have multiple file names that are in the following format:

format 1:
Filename-11

format 2:
Filename-11-99

** numbers following the Filename can be any random number.

I want to create an if condition to match the second file format example:

if filename pattern has "numbers-numbers", then, else...

so if i have the following strings:

Orange-01
Apples-01-02
peaches-123

it will only match Apples-01-02.

any help is greatly appreciated.

1
  • 1
    Use preg_match to solve your issue. Commented Sep 24, 2017 at 17:49

1 Answer 1

1

A possible solution is to use preg_match. You should check regular expressions syntax to learn what the following means:

if (preg_match('~\d+-\d+~', $string)) {
    // matched
} else {
    // no match
}

Do use http://regex101.com to work with regex. It is brilliant.

Sign up to request clarification or add additional context in comments.

Comments

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.