Jump to content

Regular Expression


imperium2335

Recommended Posts

Firstly there's a board for Regular Expressions, please try to keep posts in the right sections (I moved this particular one for you).

 

That's going to be a fairly easy task, a lot depends on exactly what you wish to do. This will detect if a string has a sub-string of the form 'number-space-cheese'...

 

$input = "john has 6 cheese slices";
if(preg_match('#[0-9]+ cheese\b#', $input)) {
   echo "Yes there is a number followed by a space,followed by the word cheese in the variable input";
} else {
   echo "No there isn't.";
}

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.