-1
preg_match( '/[a-z1-9]{2,5}-\d(\.\d)?/', "example.com - ABC-1.0", $match);

This is working at http://gskinner.com/RegExr/. I get the expected matches there - it matches "ABC-1.0". But not using preg_match. The matches array is empty.

Michelle Williamson
  • 2,516
  • 4
  • 18
  • 19

3 Answers3

3

You need to use delimiters when using PCRE functions. You also need the regex to be case insensitive.

preg_match('/[a-z1-9]{2,5}-\d(\.\d)?/i'
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

You can add case insensitivity inside the regex using a modifier group.
Also note that the group 1 is optional, so if it doesn't find a .number group 1 will be empty.

/(?i)[a-z1-9]{2,5}-\d(\.\d)?/

0

If you know the ABC part should always match uppercase letters, you can make it explicit by using [A-Z1-9]

Better to be explicit than vague when it comes to regexes.

abstr
  • 541
  • 2
  • 5