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
https://forums.phpfreaks.com/topic/184758-regular-expression/#findComment-975348
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.