开发者

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

开发者 https://www.devze.com 2022-12-11 13:22 出处:网络
Hay all, i need help making a regex. Th开发者_JS百科e string must contain a \"-\" and must not contain a \".\".

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

精彩评论

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