Jump to content

Need help finding right pattern

Recommended Posts

Hey, guys. Sorry, if this sound like a stupid question to you, but I am really not good with regular expressions.

I want to match full number, slash and 900000.

So, the pattern is:

[number]/[slash][any_umber or exactly 900000]

Igoogled for a while, and tried this:

$regex = '#[0-9]/[0-9]#';

However, it doesn't work as I want. Please help!

  • Like 1

Share this post

Link to post
Share on other sites

Just [0-9] (or \d for short) will only match a single digit. If you want one or more then use +.


Not sure how the "any number or exactly 900000" is supposed to work. Isn't 900000 a number too?

Share this post

Link to post
Share on other sites

At face value, this should work for you:

if ($match) {
  // matched, do something

but i have a sneaking suspicion you aren't telling us the whole story/requirements. 

Edited by .josh

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.