0
echo preg_match( '/\d[A-Z]/', 'CD' ); // Displays “0”

How can it display 0 when clearly there are characters that match the range "[A-Z]"?

Is it the way the parsing occurs?

Robert
  • 10,126
  • 19
  • 78
  • 130

1 Answers1

1

The regex /\d[A-Z]/ says that the input must have a digit first, and then an alphabet must be present.
Since the input CD doesnot contain a digit and an alphabet following it, the function returns 0.

To match more than one capital letters or digits, you can use the following regex.

/[\dA-Z]+/
Ali Shah Ahmed
  • 3,263
  • 3
  • 24
  • 22