开发者

php regex for string containing a "." and "-"

Hay all, i need help making a regex. Th开发者_JS百科e string must contain a "-" and must not contain a ".".

Can someone help me please.


You don't need a regex for that:

if (strpos($string, '-') !== false && strpos($string, '.') === false)
    //do what you want...


Don't know about php, but this should do it:

^[^.]*-[^.]*$


no need regex for this, one method is to use strpos

strpos($mystr,"-" ) !== FALSE && strpos($mystr,"." ) === FALSE
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜