开发者

What is wrong with this regular expression?

开发者 https://www.devze.com 2023-01-12 01:56 出处:网络
I\'m trying to learn some basic r开发者_如何学Goegular expression and having a hard time getting it to work.

I'm trying to learn some basic r开发者_如何学Goegular expression and having a hard time getting it to work.

What is wrong with this?

if (preg_match("[a-zA-Z0-9]{1,}", $url)) {

It must be something to do with my technique since I can hardly get any examples to work.


PHP regular expressions have a forward slash (/) on either side of them. What you want is:

preg_match("/[a-zA-Z0-9]{1,}/", $url)

I assume you realise that this just matches any alphanumeric string, right? As an aside, I find websites like this useful for testing PHP regexps.

0

精彩评论

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