jepler Posted February 6, 2007 Share Posted February 6, 2007 Hello, I'm trying to match a pattern that starts with the letters "tn" but could have a variety of characters after. I tried the following but it doesn't seem to work: if (preg_match("^tn%",$myword)) { do something... Link to comment https://forums.phpfreaks.com/topic/37290-need-help-with-preg_match/ Share on other sites More sharing options...
Tyche Posted February 6, 2007 Share Posted February 6, 2007 You need to put your Regex Pattern in delimiters, try if (preg_match("/^tn%/",$myword)) { do something... Or use strpos - it's a bit more efficient in this case e.g. if (strpos($myword,"tn")===0) { do something... Link to comment https://forums.phpfreaks.com/topic/37290-need-help-with-preg_match/#findComment-178220 Share on other sites More sharing options...
Psycho Posted February 6, 2007 Share Posted February 6, 2007 Remove the % sign as well: if (preg_match("/^tn/", $myword)) Link to comment https://forums.phpfreaks.com/topic/37290-need-help-with-preg_match/#findComment-178222 Share on other sites More sharing options...
jepler Posted February 7, 2007 Author Share Posted February 7, 2007 excellent! thanks!! Link to comment https://forums.phpfreaks.com/topic/37290-need-help-with-preg_match/#findComment-178762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.