1

When reading about PCRE Pattern Modifiers I noticed that each modifier has a string literal, which I'm familiar with using, and a constant, which I figured was fair game as an explicit alternative.

However, when referring to these constants, say like this

echo PCRE_CASELESS === "i";

I get this error

PHP Notice: Use of undefined constant PCRE_CASELESS - assumed 'PCRE_CASELESS'

Reading the manual carefully I noticed that it says

The names in parentheses refer to internal PCRE names for these modifiers

Internal to what? The fact that the documentation lists them lead me to assume that they were available somehow in the global scope.

Mark Fox
  • 8,694
  • 9
  • 53
  • 75
  • 1
    Constants of a ‘book’ in the PHP manual should be listed in the corresponding chapter, i.e. [*Predefined Constants* of *PCRE*](http://php.net/pcre.constants). If they are not listed, they probably don’t exist. Lastly, they should be contained in the return value of `get_defined_constants`. – Gumbo Jan 02 '13 at 23:04

2 Answers2

2

The documentation is referring to the names used internally in the underlying PCRE library, which is not directly accessible from PHP user space. The names are just there for convenience in the documentation.

You specify modifiers as part of the actual regex - for example, if you wanted to use the caseless modifier (i), you would use /regex/i:

preg_match('/pattern/i', ...);

See http://php.net/manual/en/regexp.reference.delimiters.php

ajshort
  • 3,684
  • 5
  • 29
  • 43
  • Thanks for your answer, although my question was geared toward using the modifiers as constants instead of string literals I appreciate your completeness. – Mark Fox Jan 02 '13 at 23:40
1

Internal to the pcre-library. They are not exposed to php userland-code. That they appear in the manual is only for information for those, who for example knows the constants from the library itself, or other languages implementations. So one see "PCRE_CASELESS" and knows, whats going on without reading the whole text again.

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • Oddly enough I was looking at your regular expression library https://github.com/CrunchPHP/RegularExpression before I asked the question and noticed that you re-defined the literals as custom constants. Now I can only assume that it was for practical and not simply stylistic reasons. – Mark Fox Jan 02 '13 at 23:43