0

I am looking for a reg exp to match 1111111/11 pattern, all numbers are integers.

I will be grateful if anyone can please help? I am not that good in regular expressions.

3
  • Could you elaborate a bit on what kind of data this is supposed to match? Commented Oct 17, 2010 at 22:45
  • 1
    Snark answer: preg_match('%1111111/11%'). Describe the pattern in more detail if you want a better answer, or explain the why patterns you've tried so far don't work. Commented Oct 17, 2010 at 23:21
  • Matt Huggins answer below worked for me and that was exactly as he described, 7 integers.. 0-9 and then a forward slash and 2 integers which can be again from 0-9. Commented Oct 18, 2010 at 10:53

2 Answers 2

1

Assuming you're trying to match 7 digits, a slash, and then 2 more digits, you'll want a regex pattern like the following:

/^[0-9]{7}\/[0-9]{2}$/

In PHP, your overall code will look something like this:

if (0 !== preg_match('/^[0-9]{7}\\/[0-9]{2}$/', $testString)) {
    // success!
}
Sign up to request clarification or add additional context in comments.

Comments

0

if your input string is like abc1234567/89def you could use:

preg_match('~\D\d{7}/\d{2}\D~', $input);

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.