tags:

views:

24

answers:

1

I'm trying to learn some basic regular 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.

+1  A: 

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.

Stephen